简体   繁体   中英

How java thread will going to work in below scenario?

假设在多线程环境中有 5 个线程 t1,t2,t3,t4,t5.... 线程 t1,t2,t3,t4 调用 wait() 方法(在 synchronized 块内),只有线程 t5 调用 notify()方法然后哪个线程将获得优先级以再次获取临界区中的锁。

The choice is arbitrary and any one of the 4 threads may be woken up. The intrinsic lock in java is not fair which will cause some of the waiting threads to wait longer than others even though they attempted to gain the lock first. A ReentrantLock can be used to grant access to the longest waiting thread if this matters for your program.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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