I have a singleThreadExecutor that I'm feeding a Runnable with a scheduledFixedDelay like this
Runnable periodic = new Runnable() { ... }
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
executor.scheduleWithFixedDelay(periodic, 1, 1, TimeUnit.MINUTES);
It will run with 1 minute delay between executions. Problem is, sometimes I need to run it "on demand". Is that possible?
I've thought about cancelling the execution, run the Runnable and restart the execution but what I would really like is some simple method thats just executes the Runnable a head of time and the reschedules it to run again in one minute.
When you want the task to run you can submit it
executor.submit(periodic);
or add it with a delay
executor.schedule(periodic, delay, units);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With