Menu

Monitor: IllegalMonitorStateException

Help
Anonymous
2010-10-04
2012-09-15
  • Anonymous

    Anonymous - 2010-10-04

    Hi,

    I have little problem using monitors: I followed the example of the ping
    monitor but calling monitors.waitForMonitor(xxx) in a test case always throws
    an IllegalMonitorStateException

    java.lang.IllegalMonitorStateException
            at java.lang.Object.wait(Native Method)
            at jsystem.framework.monitor.MonitorsManager.waitForMonitor(MonitorsManager.java:131)
    

    What do I miss? As far as I see the threads are synchronized.

    public void waitForMonitor(Monitor monitor, long timeout) throws Exception {
    ...
            synchronized (monitor) {
            t.wait(timeout);
        }
    ...
    
     
  • Anonymous

    Anonymous - 2010-10-04

    mhhh now I am wondering shouldn't be the thread synchronized?

    public void waitForMonitor(Monitor monitor, long timeout) throws Exception { 
    ... 
       synchronized (t) {
          t.wait(timeout);
        }
     ...
    
     
  • Nizan Freedman Sheinfine

    It looks as if you are right.

    t should be synchronized since the wait() is performed on it.

    did you try it?

     
  • Anonymous

    Anonymous - 2010-10-05

    Not yet. Will have a look on it later today. If it works with with t.wait() I
    will open a ticket

     
  • Anonymous

    Anonymous - 2010-10-05

    Exception does not happen if t is synchronized. I've checked it with the
    latest code from 5.6 branch

     

Log in to post a comment.