In my program I want to wait until an exact clock time is hit. For example, at 10 o'clock I want my program to print "It's 10 o'clock!" What is the best way to poll for this time without lagging the CPU but also be very accurate (within milliseconds of the time being hit). Thanks!
Asked
Active
Viewed 94 times
-2
-
2possible duplicate of [Run java thread at specific times](http://stackoverflow.com/questions/2437141/run-java-thread-at-specific-times) – Tunaki Aug 15 '15 at 13:53
-
I haven't tried anything so far, I only know about System.nanoTime() and System.currentTimeMillis() but those are only good for duration measurements. – Scooter Aug 15 '15 at 14:06
-
It's not hw, im not even doing Java in school. – Scooter Aug 15 '15 at 14:40
1 Answers
1
You can use Timer and and TimerTask.
Timer timer = new Timer();
timer.schedule(task, delay);
You can also add a 3rd parameter 'period' if you want to repeat it every ___ long.

Jon Snow
- 230
- 1
- 9