Is there any way to add a timer in java program? I mean the code will execute only after the time complete and then repeat it-self..
Asked
Active
Viewed 209 times
-2
-
Did you check the javadocs before asking? – Stephen C May 18 '17 at 07:47
-
You may also investigate the scheduling features of your OS, so that the program does not stay in memory when it is inactive. – Henry May 18 '17 at 07:49
-
Sounds like you want to schedule a job ... eg. cron ? – Wutipong Wongsakuldej May 18 '17 at 07:50
1 Answers
1
You can use the java.util.Timer
and TimerTask
classes.
In a nutshell you create a subclass of the TimerTask
class, implement the code you want to schedule by overriding the run
method, then use a Timer
instance to schedule it.

erosb
- 2,943
- 15
- 22