Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads and synchronization

 
ajay mv
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package com.home.scjp;
i am getting IllegalMonitorStateException Exception.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, and welcome to the Ranch!

When posting code, if you UseCodeTags(←click), it will be easier to read, which will make it easier for people to help you. I've added the code tags to your original post.

As for your question, if you read the docs for that exception, it explains what causes it. I'm pretty sure it's also covered in the docs for wait(), notify(), and notifyAll(). In short, you can only call X.wait(), X.notify(), or X.notifyAll() if you're inside a synchronized (X) { ... } block, or an equivalent synchronized method. If you're getting that exception, it's because you're calling one of those methods on a object you're not synchronized on.

 
ajay mv
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou Jeff
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic