简体   繁体   中英

Schedule a task using java

我需要在Web应用程序中使用Java计划任务,更重要的是具有暂停和恢复计划的能力。我知道有TimerTask和Timer,但不确定它们是否具有此暂停选项。有时间调试那段代码。谁能指出一个可以计划,暂停和恢复任务的示例?

I know you've had issues with Qartz but please give it a second look and look at the CronTrigger . And as an example on pausing a task look at this answer: Quartz Java resuming a job excecutes it many times

Have you tried a plain Thread which a boolean flag to to pause it?

Personally I would use ScheduledExecutorService with a flag.

Fundamentally the task is your code. So until your code provides facilities to pause, other frameworks can't really help. The simplest way to provide pausing is expose a public method that just calls sleep on your thread. Now the framework may call in your public method to pause(sleep) your thread.

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