0

I'm trying to make a clock desktop app and was using

Thread.sleep(1000);

inside a while(true) loop. When I was wondering how this works and might affect CPU performance, I found that ScheduledExecutorService is more preferable and claimed by some StackOverflowers to be more accurate.

What's the difference between them?

(also saw another option using swing timers, but more curious about "advanced" stuff)

EDIT: To be more specific:

From: Java 7 doc

The scheduleAtFixedRate and scheduleWithFixedDelay methods create and execute tasks that run periodically until cancelled.

Is there any difference between Thread.sleep() and these 2 methods? (threads usage, CPU consumption, precision, when is better to use one or another, etc)

ExDCode
  • 9
  • 4
  • That's a bit like asking what the difference between you taking a nap and the organizational structure of a bunch of people working on an assembly line is. You need to narrow this down to something specific and comparable. – pvg Dec 23 '16 at 00:17
  • Also, http://stackoverflow.com/questions/6183749/distinction-between-scheduledexecutorservice-and-rolling-your-own-runnable-with – Sotirios Delimanolis Dec 23 '16 at 00:47

0 Answers0