1

Hi i am new to grails and I am using quartz plug-in for scheduling jobs. I scheduled job for every 60 sec but it is actually taking more than 60 sec some times So in that case one more threads is started and the first thread is still running So can any one tell me how to execute threads sequentially one by one.

user2977940
  • 33
  • 1
  • 7
  • possible duplicate of [How to prevent concurrent execution of a job in Grails?](http://stackoverflow.com/questions/6453802/how-to-prevent-concurrent-execution-of-a-job-in-grails) – Ruben Jun 19 '14 at 11:07

1 Answers1

4

When using the Grails Quartz plugin you can simply set the concurrent property to false to avoid concurrent executions of a Job:

class MyJob {

  static triggers = {
    ...
  }

  def concurrent = false

  def execute(context) {
     ...
  }
}

If you are using Quartz as a plain dependency (not as a Grails plugin) you need to extend StatefulJob (Quartz < 2.0) or set the @StatefulJob and @DisallowConcurrentExecution annotations (Quartz >= 2.0).

Ruben
  • 9,056
  • 6
  • 34
  • 44
  • I need to set " def concurrent = false" in MyJob class above execute() method ? is it correct – user2977940 Jun 19 '14 at 06:55
  • If you are using the Grails Quartz plugin this is indeed how it is done. – Ruben Jun 19 '14 at 07:21
  • can u explain me how it works since I am new to it or else send me some link where i can know how it works – user2977940 Jun 19 '14 at 08:41
  • Are you using the Grails quartz plugin? If so you just need to create a XXXJob class in the grails-app/jobs folder. In this class you will have the execute method, triggers, etc. If you add the property “def concurrent = false” to this job class the job will not execute concurrently. – Ruben Jun 19 '14 at 10:46