This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Thread.sleep(15000) inside actionlistener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Thread.sleep(15000) inside actionlistener" Watch "Thread.sleep(15000) inside actionlistener" New topic

Thread.sleep(15000) inside actionlistener

Mike Grandmaison

Joined: Apr 14, 2004
Posts: 12

I can't seem to figure out how to refresh my serverstatusdialog with a message that says shutting down in 15 seconds and then sleeping 15 and doing a system.exit(-1).

Basically my SSD has a shutdown action called when shutdown is pressed. This action create a confirm dialog with the ok of the confirm i unbind the rmi server, set a flag to prevent more requests, and then set the text value of the textfield on the SSD to "shutting down delaying 15 seconds" and finally Thread.sleep(15000).

What happens is the SSD freezes and does not update with the text, 15 seconds passes and the application quits.

Any suggestions?

peter wooster
Ranch Hand

Joined: Jun 13, 2004
Posts: 1033
Don't use sleep. The best way to schedule an event is to use a timer. If you are in a Swing GUI, you can use the javax.swing.Timer class, which is much easier to use than the java.util.Timer. The Swing timer causes an event to be fired when the time value expires.
Mike Grandmaison

Joined: Apr 14, 2004
Posts: 12
Yeah that worked well.

Thanks for the tip!
I agree. Here's the link:
subject: Thread.sleep(15000) inside actionlistener
It's not a secret anymore!