• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to make a thread wait and restart?  RSS feed

 
selvas kumars
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!