java - Executors Schedule in different intervals -


i try schedule executors newsinglethreadscheduledexecutor send report after 10 days(from initialized of system), after 20 days(from initialized of system) , every 1st of month. tried use newsinglethreadscheduledexecutor runs every day , check if today after 10 days.. 20 days , etc. but, think have more elegant way solve executors. have idea how can improve code?

the scheduler:

   scheduler.schedulewithfixeddelay(() -> {         try {             createreport();         } catch (exception e) {             log.error("error create engagement report", e);         }     }, 1, 1, timeunit.days); 

and on createreport function - check dates.

thanks!

eventually, use scheduledexecutorservice schedule initializing in constructor:

scheduler.schedule(createtask , nextdayoftask, timeunit.days); 

so, every time createtask - re-calc when next report should out , update schedule.

public runnable createtask = new runnable() {     @override     public void run() {         // ever need          scheduler.schedule(this, nextdayoftask, timeunit.days);     } }; 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -