[英]sleep() and context switching in java threads
讓我們假設這樣的情況:
假設Thread0首先訪問lockObject ,然后Thread0休眠 1000 毫秒。
Thread0
lockObject
synchronized(lockObject) { Thread0.sleep(1000); }
Thread1也在等待訪問lockObject 。
Thread1
在這種情況下發生了什么? 由於睡眠(1000),上下文切換會暫停 1000 毫秒嗎?
當你調用Thread0.sleep(1000); ,線程不會釋放lockObject上的鎖。 所以是的,上下文切換將暫停 1000 毫秒。
Thread0.sleep(1000);
[英]Context Switching among multiple threads in Java
[英]Context switching in Java
[英]Possible to catch the OS doing Context Switching on threads?
[英]Context switching in java concrete case
[英]Is there a way to make all running threads sleep() in Java?
[英]Java Thread.sleep leaking threads?
[英]Threads in java - use sleep inside run
[英]Java thread: start and sleep threads at random time
[英]Switching between client threads in a Java server
[英]Switching between threads and letting loop finish Java
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.