如何防止在Grails中同时执行作业? [英] How to prevent concurrent execution of a job in Grails?

查看:104
本文介绍了如何防止在Grails中同时执行作业?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在grails中有一个石英工作,需要每5秒执行一次,但我需要按顺序执行。在某些情况下,工作的执行超过了5秒,在这种情况下,我并不想在先前的执行没有完成时执行。如何在grails中配置它?



(当然,整个魔法可以用一个静态易失标志完成,但不是一个很好的方法)
(我怎样才能配置这个工作是单身?)

thx

解决方案

假设你使用的是grails quartz插件,你应该可以将它添加到你的工作中:

  def concurrent = false 

Quartz插件文档

lockquote
默认情况下,作业是以并发方式执行的,所以如果你想重写这个行为,你可以使用'concurrent'属性,在这种情况下,Quartz的StatefulJob将被使用



I have a quartz job in grails, that needs to be executed in every 5s, but I need this sequentially. In some situations the execution of the job exceeds this 5s, in this case I dont't want to be executed while the previouse exection is not finished. How to configure this in grails?

(Of course the whole magic could be done with a static volatile flag, but is not a very elegant way to do this) (Also how can I configure for the job to be singleton?)

thx

解决方案

Assuming that you're using the grails quartz plugin, you should just be able to add this to your job:

def concurrent = false

From the Quartz Plugin Documentation:

"By default Jobs are executed in concurrent fashion, so new Job execution can start even if previous execution of the same Job is still running. If you want to override this behavior you can use 'concurrent' property, in this case Quartz's StatefulJob will be used"

这篇关于如何防止在Grails中同时执行作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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