Is there a way of pausing the execution without using threads?

Hi there,

I have ran into a small problem here. I have a class which has an ActionListener instance with an anonymous class which deals with actionPerformed. I also have a method in the class which returns a value. The thing is I only want to return a value only when an event has occured, for now I'm just using a while loop which does nothing and is controlled by "boolean pauseExecution", and pauseExecution is switched in the event handler. I'm thinking that there must be a better way of doing this, anybody know?

Thanks
mentarAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
you need to synchronise the block that is calling wait/notify.

eg.

synchronized (o)
{
   o.wait();
}
0
 
objectsCommented:
0
 
mentarAuthor Commented:
Thank you, however I tried that although it does work it bombards me with  "IllegalMonitorStateException: current thread not owner", the code still seems to run fine though, any ideas what's wrong?
0
 
mentarAuthor Commented:
Thanks a lot, you've really helped me out :)
0
 
objectsCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.