Meir
Meir

Reputation: 1711

Using Timer with Swing vs Thread sleep

I am building a Swing application in Java. I've read that in order to run a GUI task periodically it is recommended to use a Timer object (from javax.swing package). I am trying to understand what is the difference between using the Timer object vs using the sleep method for the Thread. Don't they both achieve the same?

Meir

Upvotes: 1

Views: 805

Answers (1)

Qwerky
Qwerky

Reputation: 18455

If you sleep the EDT your entire GUI will hang and become unresponsive until the thread wakes up. This is bad.

Upvotes: 3

Related Questions