Using the MethodInvokingJobDetailFactoryBean
使用MethodInvokingJobDetailFactoryBean
Often you just need to invoke a method on a specific object. Using the MethodInvokingJobDetailFactoryBean you can do exactly this:
經常地,你僅僅需要調用一個對象的一個方法。使用MethodInvokingJobDetailFactoryBean,你可以正確地這樣做:
<bean id="methodInvokingJobDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject"><ref bean="exampleBusinessObject"/></property>
<property name="targetMethod"><value>doIt</value></property>
</bean>
The above example will result in the doIt being called on the exampleBusinessObject (see below):
public class BusinessObject {
// properties and collaborators
public void doIt() {
// do the actual work
}
}
<bean id="exampleBusinessObject" class="examples.ExampleBusinessObject"/>
Using the MethodInvokingJobDetailFactoryBean you don't need to create one-line jobs that just invoke a method, and you only need to create the actual business object and wire up the detail object.
使用MethodInvokingJobDetailFactoryBean 你不需要創建一個在線的jobs,僅僅調用它的方法,你可以僅僅只需要創建一個實際的邏輯對象并且把它綁定到細節對象。
By default, Quartz Jobs are stateless, resulting in the possibility of jobs interfering with each other. If you specify two triggers for the same JobDetail, it might be possible that before the first job has finished, the second one will start. If JobDetail objects implement the Stateful interface, this won't happen. The second job will not start before the first one has finished. To make jobs resulting from the MethodInvokingJobDetailFactoryBean non-concurrent, set the concurrent flag to false.
缺省地,Quartz jobs是無狀態的,在jobs的可能性作為結果影響彼此。如果你限定兩個觸發器為同一個JohDetail,它在第一個job已經完成時是可能的,第二個將會開始。如果JobDetail實現了狀態接口,它將不會發生。
<bean id="methodInvokingJobDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject"><ref bean="exampleBusinessObject"/></property>
<property name="targetMethod"><value>doIt</value></property>
<property name="concurrent"><value>false</value></property>
</bean>
Note: By default, jobs will run in a concurrent fashion.