javascript
Spring定时器配置
聲明觸發器loadPortalUserLoginOrLogoutTrigger
<bean?id="quartzSchedulerFactory"?class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
????????<property?name="triggers">
????????????<list>
?????????
????????????????<ref?local="?loadPortalUserLoginOrLogoutTrigger?"/>
?????????
????????????</list>
????????</property>
????????<property?name="quartzProperties">
????????????<props>
????????????????<prop?key="org.quartz.threadPool.threadCount">30</prop>
????????????</props>
????????</property>
</bean>
定義觸發器loadPortalUserLoginOrLogoutTrigger(條件模式)
??<bean?id="loadPortalUserLoginOrLogoutTrigger"?class=?"org.springframework.scheduling.quartz.CronTriggerBean">
????????<property??name=?"jobDetail">
????????????<ref??bean=?"loadPortalUserLoginOrLogoutDetail"/>
????????</property>
????????<property?name="cronExpression">
????????????<value>0/30?*?*?*?*??</value>
????????</property>
</bean>
該觸發器設置為從0秒開始,每30秒執行一次
調用實體類PortalUserLoginOrLogout,制定調用的方法executeTask
<bean?id="loadPortalUserLoginOrLogoutDetail"?class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"?>
????????<property?name="targetObject">
????????????<ref?bean="PortalUserLoginOrLogout"/>
????????</property>
????????<property?name="concurrent"?value="false"/>
????????<property?name="targetMethod">
????????????<value>executeTask</value>
????????</property>
</bean>
聲明實體類PortalUserLoginOrLogout
<bean?id="PortalUserLoginOrLogout"?class="com.wafer.wse.device.job.impl.PortalUserLoginOrLogoutImpl"></bean>
定義接口
public?interface?PortalUserLoginOrLogout?{
/**
?*?執行計劃操作
?*/
public?void?executeTask();?
}
?
定義實現類:
?
public?class?PortalUserLoginOrLogoutImpl?implements?PortalUserLoginOrLogout{
?private?final?Logger?LOGGER?=?Logger.getLogger(PortalUserLoginOrLogoutImpl.class);
?private?LogOperatorDAO?logOperDao;
?private?DeviceIfService?deviceIfService;
?private?DeviceDAO?devicedao;
@Override
public?synchronized?void?executeTask()?{}
}
實現的方法就會在executeTask中執行,每30秒一次
轉載于:https://blog.51cto.com/tianjian/1665975
總結
以上是生活随笔為你收集整理的Spring定时器配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 谈谈你期望的大学暑期实践或你亲身体验的
- 下一篇: java.lang.NoClassDef