Skip to content
Advertisement

Tag: timertask

how to set a task to run twice a day at specified times in Java

I have a java class that is a basic task that inherits from the TimerTask class. Then I have some tasks that inherit from the basic task. for example class MyTask and I want MyTask to run twice a day at 9 and at 11.45. code: Main class: config file: How to implement this? Answer You can use ScheduledExecutorService.

TimerTask class has to run only once in java

I have a class that runs for every 10 secs, but when I execute it more than once, multiple timers are started. If one timer is already running, I want the other timer calls to be ignored. I want only one timer to be running at a given point of time. Please help. My code: Answer I want the 1st

Advertisement