java - Which thread does notify wake up? -
this question has answer here:
- how notify method works 1 answer
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
Post a Comment