现在想要获得在特定时间或者指定时间执行相应功能
有两种做法
在l中写入如下Bean
<bean id="repeatingTrigger"spring framework和spring的关系
  class="org.springframework.scheduling.timer.ScheduledTimerTask">
 
  <property name="delay">
    <value>1000</value>
  </property>
 
  <property name="period">
    <value>3600000</value>
  </property>
 
  <property name="timerTask">
    <ref bean="task" />
  </property>
 
  <property name="fixedRate">
    <value>true</value>
  </property>

</bean>
<bean id="scheduler"
  class="org.springframework.scheduling.timer.TimerFactoryBean">
  <property name="scheduledTimerTasks">
    <list>
    <ref bean="repeatingTrigger" />
    </list>
  </property>
</bean>
<bean id="task" class="com.css.wam.portlet.SampleTask">
  <property name="workService">
    <ref bean="workService" />
  </property>
  <property name="work">
    <ref bean="work" />
  </property>
</bean>
然后写SampleTask类,如下:
package com.css.wam.portlet;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import java.util.TimerTask;
import javax.servlet.ServletContext; 字串2
import org.apache.jetspeed.security.SecurityException; 字串9
import com.css.wam.service.WorkService; 字串1
@SuppressWarnings("unused")
class SampleTask extends TimerTask{    字串2
    private static final int C_SCHEDULE_HOUR = 23;//设置指定时间
    private WorkService workService;
    private List users;
    private List teams;
    private WorkPortlet work;
 
    public void setWorkService(WorkService workService) {
  this.workService = workService;
} 字串7
public void setWork(WorkPortlet work) {
  this.work = work;
} 字串4
    public SampleTask(){
    }
 
    @SuppressWarnings("unchecked")
public void run() {
 
        Calendar cal = Instance();
        try {
          users = Users();
          teams = new ArrayList();
      for(Iterator it = users.iterator(); it.hasNext();)
      {
        String teamname = GroupsByUser((());
        teams.add(teamname);
      }
            //查看当前时间与指定是否一致,一致则执行任务
            if (C_SCHEDULE_HOUR == (Calendar.HOUR_OF_DAY) ) 字串6
                workService.autoWorkOff(users, teams);    字串8

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。