Skip to content
Advertisement

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.

JavaScript

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:

JavaScript

Main class:

JavaScript

config file:

JavaScript

How to implement this?

Advertisement

Answer

You can use ScheduledExecutorService.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement