Solved

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

Posted on 2003-12-09
5
219 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:mentar
  • 3
  • 2
5 Comments
 
LVL 92

Expert Comment

by:objects
ID: 9909236
0
 

Author Comment

by:mentar
ID: 9909392
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
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 9909408
you need to synchronise the block that is calling wait/notify.

eg.

synchronized (o)
{
   o.wait();
}
0
 

Author Comment

by:mentar
ID: 9909436
Thanks a lot, you've really helped me out :)
0
 
LVL 92

Expert Comment

by:objects
ID: 9909469
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question