[concurrency-interest] Illegal IllegalMonitorStateException

Rob Griffin rob.griffin at quest.com
Mon Aug 13 22:35:32 EDT 2007


Just in case anyone else has this strange behaviour we believe that it
was caused by native code calling back into the JVM from unregistered
native threads. 

Rob Griffin.

-----Original Message-----
From: concurrency-interest-bounces at cs.oswego.edu
[mailto:concurrency-interest-bounces at cs.oswego.edu] On Behalf Of Rob
Griffin
Sent: Tuesday, 10 July 2007 4:06 PM
To: Dave Griffith
Cc: concurrency-interest at cs.oswego.edu
Subject: Re: [concurrency-interest] Illegal IllegalMonitorStateException

Dave,

I've made them final now but a search through the code shows no
assignments to these variables other than the initial ones. They are not
being altered. 

As for you other observation; yes we realize this but the code is quite
old. We are intending to go to Java 6 for the next release and rewrite a
fair proportion of this stuff to use the concurrent packages. We have a
few reinvented wheels in this application that we would like to replace
with nice shiny new round ones.

Rob Griffin.    

-----Original Message-----
From: Dave Griffith [mailto:dgriffith at bellsouth.net] 
Sent: Tuesday, 10 July 2007 2:10 PM
To: Rob Griffin
Cc: concurrency-interest at cs.oswego.edu
Subject: Re: [concurrency-interest] Illegal IllegalMonitorStateException

If the "namedQueues" and "transactions" variables aren't final, they  
should be.  If they can't be final, it most likely means they are  
being altered, and there's your problem.  Once you do that, I'm  
pretty sure your problem will go away (unless there's a VM bug I'm  
unaware of, which is certainly possible).  Note that it's not enough  
to say "the variable is never modified".  Marking fields final has  
very specific Java memory model implications, beyond the naive  
semantics.

Beyond that, it looks like you've got a pattern that could be better  
solved by using an Executor class, rather than creating your own  
QueueManager.  No need to reinvent the wheel, especially if you  
aren't sure you can make it round.

--Dave Griffith



On Jul 9, 2007, at 9:13 PM, Rob Griffin wrote:

> Hello,
>
> We are getting this intermittent exception in our application
>
> java.lang.IllegalMonitorStateException: current thread not owner
>
>       at java.lang.Object.notify(Native Method)
>       at
> com.quest.adk.threads.queues.QueueManager.removeFromQueue 
> (QueueManager.j
> ava:257)
>
> 	......
>
>
> This seems reasonable until we look at the code that throws the
> exception:
>
>     synchronized (namedQueues) {
>        namedQueues.notify();  // <---- thrown here
>     }
>
> And we also get it in another place as well:
>
>      synchronized(transactions) {
>          transactions.notifyAll();  // <-- and here!
>      }
>
> In both cases the variables are never changed by the code once they  
> are
> initialized, so it is not possible for then to reference different
> objects between one statement and the next.
>
> We are using 1.5 on Windows.
>
> java version "1.5.0_10"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_10-b03)
> Java HotSpot(TM) Server VM (build 1.5.0_10-b03, mixed mode)
>
> Anyone seen anything like this? This has just started happening in a
> mature application and we have been using this version of Java for  
> many
> months. We do have some native code called via JNI but if it was  
> running
> amok I would have expected random errors. I have checked the release
> notes for 1.5.0._12 and there is no mention of
> IllegalMonitorStateException. As well we are approaching a release for
> our product and feel uneasy about changing JVM versions at this late
> stage.
>
>
> Regards,
>
> Rob Griffin
> Quest Software
> www.quest.com
>
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
>



_______________________________________________
Concurrency-interest mailing list
Concurrency-interest at altair.cs.oswego.edu
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest






More information about the Concurrency-interest mailing list