什么是在spring启动应用程序中安排任务的最佳方法 [英] What is best way to schedule task in spring boot application

查看:122
本文介绍了什么是在spring启动应用程序中安排任务的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发基于Spring-Boot的应用程序。



我知道像@Scheduled这样的注释可以安排任务。由于我的应用程序中的用户想要在不同的时间发送邮件并且只发送一次。



我已经阅读了帖子 Spring调度任务 - 只运行一次
但奇怪的是总是新一个基于Spring的应用程序中的localExecutor。 / p>

这样,一旦用户安排发送电子邮件,我就必须为他的任务新一个本地执行人员。



那么,有没有更好的方法?

解决方案

你应该使用 quartz-scheduler 在不同时间发送邮件并仅发送一次。 - 将此作为业务逻辑放在代码中。
请参阅spring boot -quartz integration
https:// github .com / davidkiss / spring-boot-quartz-demo


I am current developing an application based on Spring-Boot.

I know that annotation like @Scheduled can schedule tasks. Since users in my application wanna send mails at different time and send only once.

I have already read the post Spring scheduling task - run only once, but it is weird always "new" an localExecutor in a Spring based application.

In that way , once a user schedule sending an email, I have to "new" an localExecutor for his task.

So , are there any better ways?

解决方案

you should use quartz-scheduler and send mails at different time and send only once.- put this as a business logic in your code. Please see for spring boot -quartz integration https://github.com/davidkiss/spring-boot-quartz-demo

这篇关于什么是在spring启动应用程序中安排任务的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆