Pat*_*Pat 4 java spring quartz-scheduler
我真正想要做的是创建一个不同时运行的Quartz作业,但也可以访问它JobExecutionContext以获得previousFireTime.这是我的目标:
// imports...
public class UtilityObject {
private SomeService someService;
@Autowired
public UtilityObject(SomeService someService) {
this.someService = someService;
}
public void execute(JobExecutionContext ctx) throws JobExecutionException {
Date prevDate = ctx.getPreviousFireTime();
// rest of the code...
}
}
Run Code Online (Sandbox Code Playgroud)
这是我如何配置我的bean:
<bean name="utilityBean" class="UtilityObject" />
<bean id="utilityJob"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetOjbect" ref="utilityBean" />
<property name="targetMethod" value="execute" />
<property name="concurrent" value="false" />
</bean>
<bean name="utilityTrigger"
class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="utilityJob" />
<property name="startDelay" value="5000" />
<property name="repeatInterval" value="20000" />
</bean>
Run Code Online (Sandbox Code Playgroud)
当我尝试运行它时,它在创建bean时失败了
NoSuchMethodException:UtilityJob.execute()
有任何想法吗?
方案:
在阅读了skaffman的回答之后,我能够让我的解决方案正常运行.使用我拥有的触发器,我知道名字是,并且发现默认组是'DEFAULT'.我让我的类扩展了QuartzJobBean类,然后添加了这段代码:
protected void executeInternal(JobExecutionContext ctx)
throws JobExecutionException {
boolean isRunning =
(ctx.getScheduler().getTriggerState("utilityTrigger", "DEFAULT") ==
Trigger.STATE_BLOCKED);
if (isRunning) {
// run the job
}
}
Run Code Online (Sandbox Code Playgroud)
抱歉奇怪的格式; 这些是长队!
dar*_*nmc 11
可以使用arguments属性MethodInvokingJobDetailFactoryBean以与spring相同的方式传递参数MethodInvokingFactoryBean.
例如:
<bean id="myJob"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="myBean" />
<property name="targetMethod" value="myMethod" />
<property name="arguments">
<list>
<value>greetings</value>
<ref bean="anotherBean"/>
</list>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9383 次 |
| 最近记录: |