I am getting an Exception everytime I run the following multithreaded code with Monitors.
http://pastebin.com/jTGR98W9 http://pastebin.com/hKvuDX2d
Everytime I perform a condition signal, I get an exception, which says that it should be exclusive, it is however exclusive, given that it is synchronized. Or am I doing something wrong?
Thanks
You are mixing the old intrinsic locks and their signaling mechanism (
synchronized
,wait
andnotify
) with the newLock
andCondition
classes, though they don't have any relationship. This is a source for confusion, so I'd stick to one of them (preferablyLock
andCondition
).Your problem is probably caused by not holding the lock that is associated to the condition when you are calling
signal()
. Surround the methods with calls tolock()
andunlock():
The same needs to be done for the other
synchronized
methods.