Reputation: 1711
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
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