File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes How to make a thread wait and restart? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "How to make a thread wait and restart?" Watch "How to make a thread wait and restart?" New topic
Author

How to make a thread wait and restart?

selvas kumars
Ranch Hand

Joined: Jan 06, 2001
Posts: 115
Hi folks,
my requirement is like from main thread i will start
new thread ,Once the new starts the main thread has to be in wait
state..and once the new thread stops i have to start the old one again How to go about it..
The following is where i require..
1)From the main program i will call a Jdialog window.Now the main thread had to wait. The JDialog has to be in a seperate thread, once i click yes or no, then main thread to continue its execution.How to go about??
Thanks & Regards,
silva.
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Two things. First, why would you spawn a second thread when the process evidently doesn't need one at all? Second, any Swing (or AWT) widget lives its entire life in the Swing event dispatcher thread - Swing isn't threadsafe.
If you want your main thread to wait for an GUI event, you can create a new Object() as a semaphore (or recycle an existing object), wait() on it in the main thread, and have the button event handler call notify() on it.
- Peter
bin jian
Greenhorn

Joined: Jan 03, 2002
Posts: 6
try this link,
web page contains DiningPhilosophers applet
source of DiningPhilosophers demo
wish this help you!
[ January 03, 2002: Message edited by: bin jian ]
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Or you could just use t1.join() in your main method after you start it. That way the main thread will wait until the other is completed. Won't stop other threads from accessing the thread object, but main won't do anything until the thread stops.
Jason
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to make a thread wait and restart?
 
Similar Threads
How can i start multiple threads ??
Will a started thread run to completion in this example?
How to find if a thread has finished execution?
Waiting on a JDialog
wait and notify