gpt4 book ai didi

java - java线程是在系统中使用实时定时器还是它有自己的专用定时器?

转载 作者:搜寻专家 更新时间:2023-11-01 01:23:47 25 4
gpt4 key购买 nike

有谁知道 Thread.sleep(1000) 方法使用什么定时器?Thread 是否使用实时系统计时器或是否有自己的专用计时器?

预先感谢您的回答。

最佳答案

Java 语言规范将此方法的语义细节推迟到底层系统。因此,行为将取决于哪个 JVM 实现、您正在使用哪个 rt.jar 以及应用程序运行在哪个操作系统和硬件上。

这就是关于 JLS 中方法的全部内容。 (第 17 章:线程和锁):

17.9 Sleep and Yield

Thread.sleep causes the currently executing thread to sleep (temporarily cease execution) for the specified duration, subject to the precision and accuracy of system timers and schedulers. The thread does not lose ownership of any monitors, and resumption of execution will depend on scheduling and the availability of processors on which to execute the thread.

Neither a sleep for a period of zero time nor a yield operation need have observable effects.

It is important to note that neither Thread.sleep nor Thread.yield have any synchronization semantics. In particular, the compiler does not have to flush writes cached in registers out to shared memory before a call to Thread.sleep or Thread.yield, nor does the compiler have to reload values cached in registers after a call to Thread.sleep or Thread.yield.

关于java - java线程是在系统中使用实时定时器还是它有自己的专用定时器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4757334/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com