3 notifyAll limitations — solved with conditionVar@@

Classic Object.notifyAll()
* can’t control which subset of waiting threads NOT to wake up.
* cause every thread to wake up and grab the lock, even if only some of them should.
* can’t select a single thread to wake up

Can we solve these problems by having each waiting thread use its own condition variable? Save these condition instances in a global array. Notifier can then choose one condition instance? Any scheme involving shared collection (like this global array) of condition instances requires care and feeding as access to the shared collection need synchronization.

I think condition variable is designed to be 1 : m : mm i.e.

   “1-lock/m-conditions and 1-condition/m-threads” — not 1-condition/1-thread

Condition.java API gives an example of 2 conditions on one lock. There’s another sample code P168 [[java 1.5 Tiger, A developer’s notebook]]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s