Reputation: 925
I'm grappling with a strange problem and driving me nuts.
I've followed the nice tutorial here:http://www.mkyong.com/spring/spring-quartz-scheduler-example/
I've opted for the cron trigger and just changed it to run at 10:45 am. But the once the job is started, it is going in a loop and printing the same message over and over again.
here's my software:
I've not changed the spring-quartz.xml that came along with the above tutorial (except for the cron expression).
EDITED (Added beans xml content):
<bean id="runMeTask" class="com.test.RunMeTask" />
<bean name="runMeJob"
class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.test.RunMeJob" />
<property name="jobDataAsMap">
<map>
<entry key="runMeTask" value-ref="runMeTask" />
</map>
</property>
</bean>
<!-- Simple Trigger -->
<bean id="simpleTrigger"
class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="runMeJob" />
<property name="repeatInterval" value="5000" />
<property name="startDelay" value="1000" />
</bean>
<!-- Cron Trigger -->
<bean id="cronTrigger"
class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="runMeJob" />
<property name="cronExpression" value="* 45 10 * * ?" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobDetails">
<list>
<ref bean="runMeJob" />
</list>
</property>
<property name="triggers">
<list>
<ref bean="cronTrigger" />
</list>
</property>
</bean>
EDITED (added code job and task code):
public class RunMeTask
{
public void printMe() {
try{
System.out.println("Run Me ~");
}
catch(Exception e){
e.printStackTrace();
}
}
}
This is the job class
public class RunMeJob extends QuartzJobBean
{
private RunMeTask runMeTask;
public void setRunMeTask(RunMeTask runMeTask) {
this.runMeTask = runMeTask;
}
protected void executeInternal(JobExecutionContext context){
try{
runMeTask.printMe();
}
catch(Exception e){
e.printStackTrace();
}
}
}
Upvotes: 2
Views: 1536
Reputation: 340693
Why do you think it is incorrect?
<property name="cronExpression" value="* 45 10 * * ?" />
This CRON expression means: run the job at 10:45 on every day run the job at every second of 10:45 on every day (first asterisk is second). Works as designed. Maybe in your case (run once at a given time) SimpleTrigger
is more suitable (see: SimpleTriggerBean
).
UPDATE: if you want to run the job once at 10:45 every day, this is the correct expression:
<property name="cronExpression" value="0 45 10 * * ?" />
Upvotes: 4