<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>redstream &#187; Quartz</title>
	<atom:link href="http://www.redstream.nl/tag/quartz/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.redstream.nl</link>
	<description>Pragmatic Integrators</description>
	<lastBuildDate>Fri, 27 Jan 2012 19:31:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Weird Quartz scheduler behaviour</title>
		<link>http://www.redstream.nl/2007/07/25/weird-quartz-scheduler-behaviour/</link>
		<comments>http://www.redstream.nl/2007/07/25/weird-quartz-scheduler-behaviour/#comments</comments>
		<pubDate>Wed, 25 Jul 2007 05:54:44 +0000</pubDate>
		<dc:creator>Pascal Alma</dc:creator>
				<category><![CDATA[Spring Framework]]></category>
		<category><![CDATA[Quartz]]></category>

		<guid isPermaLink="false">http://www.pascalalma.net/?p=55</guid>
		<description><![CDATA[As I posted before here I am using Quartz scheduler to schedule some batch jobs. It seemed to work fine but now while we were testing our application it appeared Quartz was showing some weird behaviour. I have scheduled 3 &#8230; <a href="http://www.redstream.nl/2007/07/25/weird-quartz-scheduler-behaviour/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2007%2F07%2F25%2Fweird-quartz-scheduler-behaviour%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2007%2F07%2F25%2Fweird-quartz-scheduler-behaviour%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>As I posted before <a href="http://www.redstream.nl/2007/04/26/scheduling-with-spring-and-quartz/.net/?p=31">here</a> I am using Quartz scheduler to schedule some batch jobs. It seemed to work fine but now while we were testing our application it appeared Quartz was showing some weird behaviour. I have scheduled 3 jobs, each with it&#8217;s own trigger in one scheduler. However, 2 of the jobs are only triggered if the trigger of other remaining job has been fired before.<span id="more-55"></span><br />
Of course I checked my configuration multiple times but I couldn&#8217;t find something wrong with it. After lots of testing and debugging I solved the issue by replacing the rescheduleJob() command with a simple deleteJob() and scheduleJob().</p>
<p>Here is the relevant original piece of code:</p>

<div class="wp_codebox"><table><tr id="p553"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p55code3"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>job <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    nextRun <span style="color: #339933;">=</span> scheduler.<span style="color: #006633;">scheduleJob</span><span style="color: #009900;">&#40;</span>trigger.<span style="color: #006633;">getJobDetail</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, trigger<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    nextRun <span style="color: #339933;">=</span> scheduler.<span style="color: #006633;">rescheduleJob</span><span style="color: #009900;">&#40;</span>trigger.<span style="color: #006633;">getFullName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, trigger.<span style="color: #006633;">getGroup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, trigger<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>After replacing this code with the next piece it worked fine again, although I cannot explain why&#8230;.</p>

<div class="wp_codebox"><table><tr id="p554"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p55code4"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>job <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    nextRun <span style="color: #339933;">=</span> scheduler.<span style="color: #006633;">scheduleJob</span><span style="color: #009900;">&#40;</span>trigger.<span style="color: #006633;">getJobDetail</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, trigger<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    scheduler.<span style="color: #006633;">deleteJob</span><span style="color: #009900;">&#40;</span>trigger.<span style="color: #006633;">getJobDetail</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, trigger.<span style="color: #006633;">getJobDetail</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getGroup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    nextRun <span style="color: #339933;">=</span> scheduler.<span style="color: #006633;">scheduleJob</span><span style="color: #009900;">&#40;</span>trigger.<span style="color: #006633;">getJobDetail</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, trigger<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2007/07/25/weird-quartz-scheduler-behaviour/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scheduling with Spring and Quartz</title>
		<link>http://www.redstream.nl/2007/04/26/scheduling-with-spring-and-quartz/</link>
		<comments>http://www.redstream.nl/2007/04/26/scheduling-with-spring-and-quartz/#comments</comments>
		<pubDate>Thu, 26 Apr 2007 06:20:56 +0000</pubDate>
		<dc:creator>Pascal Alma</dc:creator>
				<category><![CDATA[Spring Framework]]></category>
		<category><![CDATA[Quartz]]></category>

		<guid isPermaLink="false">http://www.pascalalma.net/?p=31</guid>
		<description><![CDATA[Just a small post about something I noticed in Quartz. I wanted to offer the user a screen with functionality so they could (re)schedule a batch job which then would do all kinds of batch stuf. To schedule the job &#8230; <a href="http://www.redstream.nl/2007/04/26/scheduling-with-spring-and-quartz/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2007%2F04%2F26%2Fscheduling-with-spring-and-quartz%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2007%2F04%2F26%2Fscheduling-with-spring-and-quartz%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Just a small post about something I noticed in Quartz. I wanted to offer the user a screen with functionality so they could (re)schedule a batch job which then would do all kinds of batch stuf. To schedule the job in my application I used the following Java code:</p>

<div class="wp_codebox"><table><tr id="p319"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code" id="p31code9"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> resetScheduleJob<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> CustomSystemException <span style="color: #009900;">&#123;</span>
&nbsp;
      StdScheduler scheduler <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>StdScheduler<span style="color: #009900;">&#41;</span>MyQueueContext.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getBean</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;scheduler&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      CronTriggerBean trigger <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>CronTriggerBean<span style="color: #009900;">&#41;</span>MyQueueContext.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getBean</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;batchProducerTrigger&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
           trigger.<span style="color: #006633;">setCronExpression</span><span style="color: #009900;">&#40;</span>getCronExpression<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
           scheduler.<span style="color: #006633;">scheduleJob</span><span style="color: #009900;">&#40;</span>trigger.<span style="color: #006633;">getJobDetail</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, trigger<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aparseexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ParseException</span></a> pe<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> CustomSystemException <span style="color: #009900;">&#40;</span>pe<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>SchedulerException se<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> CustomSystemException <span style="color: #009900;">&#40;</span>se<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      LOG.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Next run will be at: &quot;</span> <span style="color: #339933;">+</span> trigger.<span style="color: #006633;">getNextFireTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getCronExpression<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// Small trick to get the hours of the day correct.</span>
      <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> hours <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>startTime <span style="color: #339933;">&gt;</span> endTime<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         hours <span style="color: #339933;">=</span> endTime <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;-23,0-&quot;</span> <span style="color: #339933;">+</span> startTime<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>startTime <span style="color: #339933;">&lt;</span> endTime<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         hours <span style="color: #339933;">=</span> startTime <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;-&quot;</span> <span style="color: #339933;">+</span> endTime<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
         hours <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;0&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;0 0/&quot;</span> <span style="color: #339933;">+</span> interval <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; &quot;</span> <span style="color: #339933;">+</span> hours <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; ? * &quot;</span> <span style="color: #339933;">+</span> days<span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><span id="more-31"></span><br />
So this code runs fine the first time when it is called. But when you call it the second time (after the job exists) you will get:</p>
<p> <code>org.quartz.ObjectAlreadyExistsException: Unable to store Job with name: 'batchProducerJob' and group: 'DEFAULT', because one already exists with this identification.</code></p>
<p>So I rewrote my code to:</p>

<div class="wp_codebox"><table><tr id="p3110"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p31code10"><pre class="java" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> resetScheduleJob<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> CustomSystemException <span style="color: #009900;">&#123;</span>
      StdScheduler scheduler <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>StdScheduler<span style="color: #009900;">&#41;</span>MyQueueContext.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getBean</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;scheduler&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      CronTriggerBean trigger <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>CronTriggerBean<span style="color: #009900;">&#41;</span>MyQueueContext.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getBean</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;batchProducerTrigger&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
         trigger.<span style="color: #006633;">setCronExpression</span><span style="color: #009900;">&#40;</span>getCronExpression<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
         scheduler.<span style="color: #006633;">rescheduleJob</span><span style="color: #009900;">&#40;</span>job.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, job.<span style="color: #006633;">getGroup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, trigger<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
         scheduler.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aparseexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ParseException</span></a> pe<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> CustomSystemException <span style="color: #009900;">&#40;</span>pe<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>SchedulerException se<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> CustomSystemException <span style="color: #009900;">&#40;</span>se<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      LOG.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Next run will be at: &quot;</span> <span style="color: #339933;">+</span> trigger.<span style="color: #006633;">getNextFireTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Now this code won&#8217;t fail if you call it several times&#8230;.. Actually, it doesn&#8217;t do anything! I would expect an exception if the scheduler must have an existing job before it can reschedule one. But nothing there, I only found out that my job wasn&#8217;t started at all. So the trick is to check if there is a job with the same name, and if one is found, do the reschedule, otherwise the &#8216;normal&#8217; schedule. Since I wasn&#8217;t expecting this behaviour I thought may be there are more persons running into this so here is the solution:</p>

<div class="wp_codebox"><table><tr id="p3111"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code" id="p31code11"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> resetScheduleJob<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> CustomSystemException <span style="color: #009900;">&#123;</span>
      StdScheduler scheduler <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>StdScheduler<span style="color: #009900;">&#41;</span>MyQueueContext.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getBean</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;scheduler&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      CronTriggerBean trigger <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>CronTriggerBean<span style="color: #009900;">&#41;</span>MyQueueContext.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getBean</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;batchProducerTrigger&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
         trigger.<span style="color: #006633;">setCronExpression</span><span style="color: #009900;">&#40;</span>getCronExpression<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
         JobDetail job <span style="color: #339933;">=</span> scheduler.<span style="color: #006633;">getJobDetail</span><span style="color: #009900;">&#40;</span>trigger.<span style="color: #006633;">getJobDetail</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, trigger.<span style="color: #006633;">getJobDetail</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getGroup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         LOG.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Job found = &quot;</span> <span style="color: #339933;">+</span> job<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
         <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>job <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
           scheduler.<span style="color: #006633;">scheduleJob</span><span style="color: #009900;">&#40;</span>trigger.<span style="color: #006633;">getJobDetail</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, trigger<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            scheduler.<span style="color: #006633;">rescheduleJob</span><span style="color: #009900;">&#40;</span>job.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, job.<span style="color: #006633;">getGroup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, trigger<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
&nbsp;
         scheduler.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aparseexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ParseException</span></a> pe<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> CustomSystemException <span style="color: #009900;">&#40;</span>pe<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>SchedulerException se<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> CustomSystemException <span style="color: #009900;">&#40;</span>se<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      LOG.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Next run will be at: &quot;</span> <span style="color: #339933;">+</span> trigger.<span style="color: #006633;">getNextFireTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And to make this example complete here is my Spring configuration:</p>

<div class="wp_codebox"><table><tr id="p3112"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code" id="p31code12"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE beans SYSTEM &quot;../dtd/spring-beans.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;batchProducerJob&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;targetObject&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;batchProducer&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;targetMethod&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;start&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;batchProducerTrigger&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.scheduling.quartz.CronTriggerBean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jobDetail&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;batchProducerJob&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;scheduler&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.scheduling.quartz.SchedulerFactoryBean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
           <span style="color: #808080; font-style: italic;">&lt;!-- intentionally left empty --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;batchProducerScheduler&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;net.pascalalma.batch.schedulers.BatchProducerScheduler&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;startTime&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${batch.produce.starthour}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;endTime&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${batch.produce.endhour}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;interval&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${batch.produce.interval}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;days&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${batch.produce.days}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2007/04/26/scheduling-with-spring-and-quartz/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

