Arnob Dey wrote:
Simple answer is: It's simply not possible. Thread can only release the lock and it has no control over who gets the lock next.
Now the stupid question is: What about Thread.join()? How that works out?
Not exactly sure how it is that related, meaning the two points in your topic. Thread join() is more related to the use of the wait and notify mechanism, than about the synchronization lock required by the mechanism.
Anyway, when the thread has completed (and is no longer alive), one of the cleanup tasks is to send a notifyAll(). And once this call releases the lock, it doesn't really care who gets control of the lock next. They will all take turns getting the lock, waking up, releasing the lock, and returning from the join() method.
Henry