Solved

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

Posted on 2003-12-09
5
215 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now