简体   繁体   English

为什么使用 TCP 使用一个不能总是精确的基本定时器,而 Java 中的定时器总是精确的?

[英]why use TCP use a basic timer which cannot be always exact whereas timer in java is always precise?

I am reading "TCP/IP illustrated", and the book illustrates that kernel implements a unit-timer like 500ms for TCP and all other TCP timers use this unit-timer.我正在阅读“TCP/IP 说明”,这本书说明内核为 TCP 实现了一个像 500 毫秒这样的单位计时器,而所有其他 TCP 计时器都使用这个单位计时器。 But the first period cannot be exact.但第一个时期不能准确。 For example, a retransmission timer is 12 units (6s), but the first time period may be in the middle so the actual time may be 5.5-6s.比如一个重传定时器是12个单位(6s),但是第一个时间段可能在中间,所以实际时间可能是5.5-6s。

On the contrary, when in java, it is easy to implement Thread.sleep(5000ms) which is precise and not a range.相反,在java中,很容易实现精确而不是范围的Thread.sleep(5000ms)。

So whey TCP timer cannot be exact whereas java can?那么乳清 TCP 计时器不能精确,而 java 可以?

I kind of understand it and wanna check my answer.我有点理解它并想检查我的答案。 Java and Tcp timer both use a unit timer to count for the time period. Java 和 Tcp 计时器都使用单位计时器来计算时间段。 The unit is limited by CPU which can be thousands of MHz meaning the clock is ns level.该单位受 CPU 限制,CPU 可以是数千 MHz,这意味着时钟是 ns 级。 So the unit timer has a good choice of the granularity of the time.所以单位定时器对时间的粒度有很好的选择。 As for web service which tends to be slow, TCP chooses hundreds of ms while for java a tinier unit is chosen.对于速度较慢的 Web 服务,TCP 选择了数百毫秒,而对于 Java,则选择了更小的单位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM