简体   繁体   中英

Java ScheduledExecutorService behavior?

I have the following code:

ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1, nameOfPool);
scheduler.scheduleAtFixedRate (new Runnable() {
    @Override
    public void run() {
       if (someCondition) {
           return;
       }   
    }
}, 0L, 30, TimeUnit.MINUTES);

Might be a dumb question, but does run() still get run every 30 minutes, even if I return; inside of the run() body, having met someCondition ?

Yes, of course.

What would happen even if someCondition was not met? The flow would drop out of the bottom of run which is the same as a return isn't it.

Even if the run method did not return, then they may be problems as per

the task will only terminate via cancellation or termination of the executor. If any execution of this task takes longer than its period, then subsequent executions may start late, but will not concurrently execute.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM