ssh2做的一个小网站中,想做个定时器,在web服务器启动后,在每天晚上12点时,执行一个Action中的一个方法,有什么简单的方式可以实现。

解决方案 »

  1.   

    用定时器做啊!!!Timer
      

  2.   

    可以参考这篇http://xuepiaoqiyue.blog.51cto.com/4391594/857571
      

  3.   

    参考2L的,搜下,然后引入jar包,改改配置文件就好啦。~
      

  4.   

    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
      http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd"><bean id="AXXXXXXXX" class="你的action路径"/>
    <!-- 定时任务 -->
    <bean id="myJob"
    class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
    <property name="targetObject">
    <ref bean="AXXXXXXXX" />
    </property>
    <property name="targetMethod">
    <value>要执行的方法名</value>
    </property>
    <property name="concurrent" value="false" />
    </bean> <!--  -->
    <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
    <property name="jobDetail" ref="myJob">
    </property>
    <property name="cronExpression">
    <value>0 0 6 * * ?</value><!--设置定时时间-->
    </property>
    </bean> <!-- 启动调度 -->
    <bean id="jobScheduler" autowire="no"
    class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="triggers">
    <list>
    <ref bean="cronTrigger" />
    </list>
    </property>
    </bean>
    </beans>