• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sleep method

 
Suat Ugurlu
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
In my main program, I load a class and invoke a method in that
class.
In invoked method in the class , I create a user interface for some tasks and after getting user input I wait for a while.
I call Thread.currentThread().sleep(3) for waiting 3 seconds.
In that time my main program window blocks also for 3 seconds.

My main program window and the window waiting for the user input must be working in two different threads!. So sleep methods shouldn't block all
windows , am I right?

What can I do in order make only second invoked method thread waits while
my main program window runs.

Regards,Suat.
 
Yaroslav Chinskiy
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

First of all Thread.sleep(3) is 3 millsec not seconds.
The GUI runs in different thread and if you want the current thread to wait while GUI completes some task you can try SwingUtility.invokeAndWait() method.

Also, if you want thread T1 to wait until thread T2 completes, you can use T2.join()

Hope that helps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!