更新时间:2022-03-15 23:29:04
synchronized
的获取遵循non-fair
锁定策略.也就是说,在阻塞时首先进入的线程可能不是第一个获取的线程.如果您想使用fair
锁,请使用new ReentrantLock(true)
synchronized
acquisition follows a non-fair
lock policy. That is, threads that enter first while blocking may not be the first to acquire. If you want a fair
lock use a new ReentrantLock(true)