I donβt know if this is logical for your application, but change
Thread.currentThread().wait();
to
lock.wait();
should make an exception that will not be thrown. Please feedback.
EDIT:
in both places and also change
Thread.currentThread().notifyAll();
EDIT ^ 2:
For an explanation, look here and here.
:
synchronized(object) {
the object from line 1 must be the same object as line 2, because if they are not the same IllegalMonitorStateException exception
Thrown to indicate that the thread tried to wait on the objectβs monitor or notify other threads that are waiting for the object to be monitored without owning the specified monitor.
where ownership of the monitor means that it must be inside the synchronized block (as shown in lines 1,2)
source share