日期:2014-05-17 浏览次数:20848 次
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" autowire="no" lazy-init="true">
<property name="triggers">
<list>
<ref bean="testTrigger"/>
</list>
</property>
<property name="autoStartup" value="true"/>
</bean>
<bean id="testTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean" lazy-init="true">
<property name="jobDetail" ref="testJobDetail"/>
<property name="cronExpression" value="*/1 * * * * ?"/><!-- 每隔1秒钟触发一次 -->
</bean>
<bean id="testJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" lazy-init="true">
<property name="targetObject" ref="testJob"/>
<property name="targetMethod" value="execute"/>
<property name="concurrent" value="false"/>
<!-- 是否允许任务并发执行。当值为false时,表示必须等到前一个线程处理完毕后才再启一个新的线程 -->
</bean>
<bean id="testJob" class="com.zakc.yhpc.test.TestJob" lazy-init="true"/>
public class TestJob {
public void execute() {
try {
// 业务逻辑代码调用
System.out.println("时间[" + new java.util.Date().toLocaleString()
+ "]----->大家好啊!");
Service service = new Service();
//执行到这里就不会输出下面那句
System.out.println(123);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}