Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how do i compare an object based on two fields 6 48
session migration servlets 2 24
map related example 6 30
factorial example 4 34
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

929 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

10 Experts available now in Live!

Get 1:1 Help Now