简体   繁体   中英

Scheduled task keeping application alive

I have an application, made with javafx, which schedules a runnable to run every day, using scheduledFuture = scheduledExecutorService.scheduleAtFixedRate(runnable, initialDelay, 24*60*60*1000, TimeUnit.Milliseconds)

Even though I cancel this task using scheduledFuture.cancel(true) , my application is kept alive, in the background, after the user has closed it.

I'm pretty sure this scheduling is the only thing keeping the application alive. If I don't schedule it, the application closes all right.

Calling shutdown() on the scheduledExecutorService allowed the program to shut down normally.

scheduledExecutorService.shutdown();

According to the javadocs,

Initiates an orderly shutdown in which previously submitted tasks are executed

Whereas calling cancel(true) just cancels the task, leaving the executor service alive, shutdown() kills the executor service as well, allowing the program to exit.

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