码迷,mamicode.com
首页 > 编程语言 > 详细

Spring定时器配置

时间:2015-06-27 00:01:37      阅读:226      评论:0      收藏:0      [点我收藏+]

标签: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秒一次

Spring定时器配置

标签:spring

原文地址:http://tianjian.blog.51cto.com/3549910/1665975

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!