ssh使用 TimerTask空指针错误 ssh 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 TimerTask run里面调用这个类方法的地方的代码发出来看下. 你是怎么获取当前类实例的(AutoComment2) 不好意思,看不太懂。。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。 synchroDataTimerTask 里面没有注入errorApplyService.加个@Autowired注解试下,不行就在<bean id="synchroDataTimerTask" class="com.surfkj.wlgzbx.action.AutoComment2"></bean>里面把errorApplyService属性加上 肯定是 errorApplyService 没注入 另外建议 不要开启服务器就调用这个run 嗯。是没有注入。已经改好了。十分谢谢。顺便问下。我想做的是自动评价,就是服务器后台自动搜索符合条件的,然后修改数据库里评价这个字段。如果不是开启服务器就调用这个run,该怎么操作比较好? while(rs.next())//为什么这条while只循环了一次?大神求解啊 数字到相应的单词转化 报表 试用期过了跟软通动力签合同两年,如果期间跳槽会不会有什么后果? sql语句中有int类型时,该怎么表示 刚开始用MQ,问一下 struts-Menu可以配置中文目录么 大侠救命!JDBC访问临时表跟访问一般表一样的吗? 高分请教jbuilder开发entity bean的完整示例。 关于poi操作word 微信开发平台 群发成功后 怎么获取推送的XML。 事件推送群发结果 马士兵上的struts的问题各位大神指导解决!
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。
<bean id="synchroDataTimerTask" class="com.surfkj.wlgzbx.action.AutoComment2"></bean>里面把errorApplyService属性加上
顺便问下。我想做的是自动评价,就是服务器后台自动搜索符合条件的,然后修改数据库里评价这个字段。如果不是开启服务器就调用这个run,该怎么操作比较好?