java - Which thread does notify wake up? -


this question has answer here:

imagine have 3 threads wait condition, , 4th thread notify condition.

now, 3 wait threads run , enter waiting state. once done, 4th thread runs , calls notify once.

how notify determine thread wake up? thread called wait first thread, thread called wait last, or based on other condition?

assume wait , notify uses same lock.

to knowledge, there no special bookkeeping - meaning selection made "randomly".

so says javadoc:

if threads waiting on object, 1 of them chosen awakened. choice arbitrary , occurs @ discretion of implementation.

thus theoretically possible jvm implementation decides enact specific order; shown - default can't expect order. shouldn't write code relies on such specific order either.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -