Explore Courses Blog Tutorials Interview Questions
0 votes
in Java by (4k points)
I am using multi-threading in java for my program. I have run thread successfully but when I am using Thread.wait(), it is throwing java.lang.IllegalMonitorStateException. How can I make a thread wait until it will be notified?

1 Answer

0 votes
by (46k points)

You need to be in a synchronized block in order for Object.wait() to work.

Also, I recommend looking at the concurrency packages instead of the old school threading packages. They are safer and way easier to work with.

Happy coding.

I assumed you meant Object.wait() as your exception is what happens when you try to gain access without holding the objects lock.

Browse Categories