Skip to content
Advertisement

wait() and notify() method , always IllegalMonitorStateException is happen and tell me current Thread is not Owner Why?

JavaScript

Advertisement

Answer

You need to hold the lock on the object you want to wait on (you can only call it within a synchronized block).

Also, calling wait on a Thread is very unusual and probably not what you want.

I am not sure what you are trying to do, but could you be confusing wait with sleep?

If you want to wait for another thread to finish, that would be anotherThread.join().

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement