You should only invoke wait
on the object that you have acquired lock on.
In your code, you have acquried lock on Thread.currentThread()
, but you are invoking it on ob
, which will throw IllegalMonitorStateException
.
So, you should rather change your synchronized block to: -
synchronized (ob) {
}