• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sleep method

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I child proofed my house but they still get in. Distract them with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic