本文介绍了Grails创建例程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我在数据库中有一个特定信息,需要在一天的特定时间通过电子邮件为特定用户发送特定信息.

Let's say, i have a specific information in the database that needs to be sent for a specific user by email in a specific time of the day.

a)如何在Grails中创建一个例程,该例程基本上是始终在运行的动作-而不与任何事件相关联?假设,每个小时运行一次该操作.

a) How can i create a routine in Grails, which is basically an action that is always running - without being associated with any event? Let's say, every hour that action is runned.

我在想这样的事情:

while(true){

...
myCodeHere
...
wait 30minutes
}

这会真正起作用吗?没有太多的处理?而且无论如何,我如何才能永久执行一项操作.我有这样做的特定方法吗?提前致谢,RR

Will this actually work? Without too much processing? And how can i have an action permanently running no matter what. I there is a specific way of doing this?Thanks in advanced,RR

推荐答案

避免使用石英和插件,您可以使用纯Spring框架

Avoiding quartz and plugins you may use pure Spring Framework

1)添加到容器

<task:annotation-driven executor="executor" scheduler="scheduler"/>
<task:executor id="executor" pool-size="5"/>
<task:scheduler id="scheduler" pool-size="10"/>

(不要忘记定义任务和tx命名空间)

(do not forget to define task and tx namespaces)

2)创建一些bean并添加方法

2) Create some bean and add method

@Scheduled(fixedDelay=4000)
public void method() {
  // do something every 4 seconds
}

完成!有关更多信息,请参见 spring框架

finish!For more info see spring framework

这篇关于Grails创建例程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 15:15