Exi*_*xia 19 java spring spring-mvc
我目前正在开发一个基于Spring-Boot的应用程序.
我知道像@Scheduled这样的注释可以安排任务.由于我的应用程序中的用户想要在不同的时间发送邮件并且只发送一次.
我已经阅读过Spring调度任务 - 只运行一次,但在基于Spring的应用程序中总是"新"一个localExecutor很奇怪.
这样,一旦用户安排发送电子邮件,我就必须为他的任务"新"一个localExecutor.
那么,还有更好的方法吗?
Sat*_* Kr 14
您可以在@Scheduled中使用crontab
private AtomicInteger counter = new AtomicInteger(0);
@Scheduled(cron = "*/2 * * * * *")
public void cronJob() {
int jobId = counter.incrementAndGet();
System.out.println("Job " + new Date() + ", jobId: " + jobId);
}
Run Code Online (Sandbox Code Playgroud)
小智 9
你应该使用quartz-scheduler和send mails at different time and send only once.- 将它作为业务逻辑放在你的代码中.请参阅spring boot -quartz integration
https://github.com/davidkiss/spring-boot-quartz-demo
| 归档时间: |
|
| 查看次数: |
40303 次 |
| 最近记录: |