Mutli thread in Java

When I'm at @ L_ 502_ There is a synchronized method in 0 @ and if multiple threads (such as 10 threads) try to access this method and assume that a thread can access this method, complete the execution of the method and release the lock, which of the remaining 9 threads can access this method? Is there any standard mechanism to select the next thread from the pool, or will it select threads in FIFO order or randomly?

Solution

Thread scheduling in Java is platform - specific In the synchronization scheme, the order of thread execution cannot be guaranteed

Having said that, the procedure is roughly as follows:

>Preemptive scheduling algorithm is adopted > each thread gets the priority number by the JVM > select the thread with the highest priority > follow FIFO sorting among threads with the same priority

The JVM runs the thread with the highest priority You can also set the priority programmatically through the setpriority () method of the thread class

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>