This content has been marked as final. Show 3 replies
That's a really interesting question!
I can't find any documentation on this at all, and a modest attempt at performance testing suggests that neither method has a performance advantage.
The timer task method strikes me as being slightly more vulnerable to unexpected performance hits than sleep due to the number of moving parts involved.
From an initial look at the Timer class, it looks like there is far more overhead in using the scheduleAtFixedRate method, than there would be using Thread.sleep, plus I think that Thread.sleep is simply more intuitive for the developer to read and maintain.
Also, I think timer tasks are mainly used to perform a specified task at a given time interval (or Date). So the Thread.sleep and the Timer.scheduleAtFixedRate methods actually do different things, and you would hence, use them differently...
JMeter is a good commonly used tool for performance testing: