2

This is the bean code for cron scheduler. declaration for runMeTask And runMeJob

<bean id="runMeTask" class="com.ascent.fieldomobify.cornScheduler.RunMeTask"/>
<bean name="runMeJob" class="org.springframework.scheduling.quartz.JobDetailBean">
    <property name="jobClass" value="com.ascent.fieldomobify.cornScheduler.RunMeJob" />
    <property name="jobDataAsMap">
        <map>
            <entry key="runMeTask" value-ref="runMeTask" />
        </map>
    </property>
</bean>

<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
    <property name="jobDetail" ref="runMeJob"/>
    <property name="cronExpression" value="0 0 13 * * ?" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="triggers">
        <list>
            <ref bean="cronTrigger" />
        </list>
    </property>
</bean>

it get call directly from bean scheduler configuration The first class is RunMeJob

public class RunMeJob extends QuartzJobBean {
private RunMeTask runMeTask;

public void setRunMeTask(RunMeTask runMeTask) {
    this.runMeTask = runMeTask;
  }

protected void executeInternal(JobExecutionContext context)
    throws JobExecutionException {

    try {
        runMeTask.printMe();
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

  }
}

form here i call the controller's method which is having the logic Second class RunMeTask

public class RunMeTask{
@Autowired
WorkOrderController workorderContoller; 

public void setWorkorderContoller(WorkOrderController workorderContoller) {
    this.workorderContoller = workorderContoller;
  }


public void printMe() throws ParseException {
    workorderContoller.printSysOut();
  }
}
Prashant
  • 43
  • 5

1 Answers1

0

there are some scenarios where you can get that behavior, please check this thread: Java Spring @Scheduled tasks executing twice

Yander
  • 23
  • 3