• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

IllegalMonitorStateException - Different in J2ME?

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Does anyone know of a difference between J2ME and J2SE in the conditions that cause an IllegalMonitorStateException to be thrown?
When I forgot to synchronize a call to the notifyAll method in a midlet, it didn't throw an exception most of the time, even though it seems like it should have, because the current thread did not own the monitor of the object whose notifyAll method was being called.
Consider the following class (I have created this to demonstrate my question - my own original code is too full of irrelevant complications to be a good illustration of the issue).


If I create an instance of this class in a J2SE applet, the constructor throws an IllegalMonitorStateException. The exception can be eliminated by putting the notifyAll call inside a synchronized(this) {} block. All this seems to be just the way it should be.
But now, if I put the above code (without the notifyAll being synchronized) into a midlet and create an instance of the ThreadTest class, there is no exception. I have observed this on various emulators and on a Nokia series 40 phone (6610).
However, if I comment out the t.start() line, an IllegalMonitorStateException is thrown. It seems as if the existence of a waiting thread at the time of the call to notifyAll prevents the exception.
Has anybody come across this before? Am I misunderstanding something about this exception? I'd be grateful for any enlightenment.
 
reply
    Bookmark Topic Watch Topic
  • New Topic