如何安排任务每隔“N”发生一次Spring框架中的秒数
我如何连接我的 web.xml 以使任务每 n 秒发生一次。此外,我需要通过方法调用每 5 秒刷新一次服务器方法。
非常感谢提前
解决:
http://javaprogrammingtips4u .blogspot.com/2010/05/how-to-implement-task-scheduler-job.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用注释所需的例程
,但为了让 Spring 查找并识别注释,您必须声明类
Foo
所在的基包,并配置 Spring 来查找调度任务。将以下内容放入 Spring XML 配置中(并且不要忘记导入 XML 命名空间context
和task
)。或者,您可以将 @EnableScheduling 放在类声明之前,它会立即为您执行 XML 配置。
另请参见 上下文命名空间和任务命名空间。
You can annotate the desired routine using
But in order to for Spring for find and recognize the annotation you must declare which base package the class
Foo
lies in as well as configure Spring to look for scheduling tasks. Put the following in your spring XML configuration (and don't forget to import the XML namespacescontext
andtask
).Alternatively you can put @EnableScheduling before the class declaration and it does the XML config for you out of the box.
See also the context namespace and the task namespace.
您可以使用 Quartz 调度程序集成,如下所述:
http://static.springsource.org/spring/docs/2.0 .8/reference/scheduling.html
我不明白您关于刷新服务器方法的问题的第二部分。
You can use the Quartz scheduler integration as documented here:
http://static.springsource.org/spring/docs/2.0.8/reference/scheduling.html
I do not understand the 2nd part of your question about refreshing a server method.
如何使用石英和弹簧。通过拆分作业、触发器和计时器,这是高度可配置的。您还可以使用 cron 表达式并集成 JMX 之类的东西:
Spring 和 Quartz
How abt using Quartz with spring. This is highly configurable by spliting Jobs, triggers and timers up. You can also use cron expressions and integrate things like JMX:
Spring and Quartz
查看 Spring 手册,第 25 节, 任务执行和调度。当我完成这类事情时,我使用了注释,如 第 25.5 节。简而言之,在 Spring 管理的 bean 中,您可以使用
@Scheduled
注释要运行的方法,并向 applicationContext.xml 添加几行。Look at the Spring manual, section 25, Task Execution and Scheduling. When I've done this sort of thing I used annotations, described in section 25.5. In short, in a Spring-managed bean you annotate the method you want to run with
@Scheduled
and add a couple of lines to your applicationContext.xml.该表达式将在工作日每 5 秒运行一次:
要检查 cron 表达式,我使用以下方法:
This expression will run every 5 seconds in working days:
To check cron expression I'm using this method: