不好意思,看不太懂。。
Spring里我是这么配置的。
<!– 声明定时器任务 –>
<bean id=”synchroDataTimerTask” class=”com.surfkj.wlgzbx.action.AutoComment2″/>
<!– 调度定时器任务 –>
<bean id=”scheduledDayDataTimerJob” class=”org.springframework.scheduling.timer.ScheduledTimerTask”>
<property name=”timerTask”>
<ref bean=”synchroDataTimerTask” />
</property>
<property name=”delay”>
<value>10000</value>
</property>
<property name=”period”>
<value>1000000</value>
</property>
</bean>
<!– 启动定时器 –>
<bean class=”org.springframework.scheduling.timer.TimerFactoryBean”>
<property name=”scheduledTimerTasks”>
<list>
<ref bean=”scheduledDayDataTimerJob”/>
</list>
</property>
</bean>
</beans>
整个autocomment2是这样的。
package com.surfkj.wlgzbx.action;
import java.util.ArrayList;
import com.surfkj.core.entity.PageControlPersistent;
import java.util.Calendar;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TimerTask;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.apache.commons.beanutils.BeanUtils;
import org.hibernate.Query;
import org.hibernate.Session;
import com.surfkj.core.entity.HibernateSessionFactory;
import com.surfkj.core.entity.PageControlPersistent;
import com.surfkj.core.util.DBConn;
import com.surfkj.wlgzbx.entity.ErrorApplyInfo;
import com.surfkj.wlgzbx.entity.ErrorApplyTypeInfo;
import com.surfkj.wlgzbx.service.IErrorApplyService;
public class AutoComment2 extends TimerTask{
public AutoComment2(){
}
private ErrorApplyInfo errorApply;
private IErrorApplyService errorApplyService;
@SuppressWarnings({ “null”, “unchecked” })
@Override
public void run() {
try {
// TODO Auto-generated method stubList<SynchroColumn> synchroColumns = this.synchroColumnService.findAllColumns();
int y,m,d,h,mi,s;
Calendar cal=Calendar.getInstance();
/* cal.add(Calendar.DATE, -15);*/
y=cal.get(Calendar.YEAR);
m=cal.get(Calendar.MONTH)+1;
d=cal.get(Calendar.DATE);
h=cal.get(Calendar.HOUR_OF_DAY);
mi=cal.get(Calendar.MINUTE);
s=cal.get(Calendar.SECOND);
System.out.println(“////////////////////////”);
Session session = HibernateSessionFactory.getSession();
String sql = “from ErrorApplyInfo where status =””完成”” and nupdatetime between “”2000-01-01 00:00:00.000″” and “””+y+”-“+m+”-“+d+” “+h+”:”+mi+”:”+s+”.000″””;
String hql = “from ErrorApplyInfo”;
Query query = session.createQuery(sql);
List list = query.list();
for(int i = 0;i < list.size();i++){
ErrorApplyInfo ea = (ErrorApplyInfo)list.get(i);
ea.setComments(“asfasfasfs”);
errorApplyService.update(ea);
System.out.println(ea.getComments());
}
} catch (Exception e) {
e.printStackTrace();
}
}
public ErrorApplyInfo getErrorApply() {
return errorApply;
}
public void setErrorApply(ErrorApplyInfo errorApply) {
this.errorApply = errorApply;
}
public IErrorApplyService getErrorApplyService() {
return errorApplyService;
}
public void setErrorApplyService(IErrorApplyService errorApplyService) {
this.errorApplyService = errorApplyService;
}
}
我是直接开启服务器就调用这个run。