1

I need schedule a task for specified date.For example task must be invoked after 2 days at 03:00:00.But i need it periodically.Each 2 days at 03:00:00.

ExecutorService provides delay time and periodic task execution but it doesn't provide me specify date and time.So i have to implement to calculate delay time.

Is there any ready to use library?

3

Most developers use Quartz for this kind of things.

Here is how you call Quartz to execute a task every 2 days at 03:00:00 :

trigger = newTrigger()
    .withIdentity("trigger3", "group1")
    .startAt(tomorrowAt(3, 0, 0)  // 03:00:00 tomorrow
    .withSchedule(calendarIntervalSchedule()
            .withIntervalInDays(2)) // interval is set in calendar days
    .build();

Documentation:
http://www.quartz-scheduler.org/documentation/quartz-2.2.x/cookbook/BiDailyTrigger

Quartz is open source and has many triggers and backends available.
It also has a big and vibrant community, and has been popular for at least 10 years already.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.