Action代码:Iterator serviceIt = TimerServlet.serviceL.iterator();
int serviceI = 0; //创建迭加变量
while(serviceIt.hasNext()){
Topic serviceT = (Topic) serviceIt.next(); //迭代获取话题
Path.addElement("hot").setText(serviceT.getTotitle()); //添加子节点
serviceI++; //累加迭加变量
if(serviceI == 5){ //当累加变量加5时(获取5位时)、停止迭代
break;
}
}Servlet代码: @Autowired
@Qualifier("topicServiceIMPL")
private TopicService topicService; // 调用topicService
public static List<Topic> serviceL;
public void init() throws ServletException {
if(serviceL != null){
serviceL.clear();
}
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
System.out.println("存前:" + serviceL);
serviceL = topicService.findServiceTopic();
System.out.println("存后:" + serviceL);
}
}, 0, 10000);
}Service代码: public List<Topic> findServiceTopic() {;
return topicDaoIMPL.findServiceTopic();
}需实现功能:
当服务器启动则进行查询数据库存值、在规定时间内取值时不进行计算取值、到规定时间时系统自动再次进行查询存值报错:Exception in thread "Timer-2" java.lang.NullPointerException
at com.gys.util.TimerServlet$1.run(TimerServlet.java:31)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
at com.gys.util.TimerServlet$1.run(TimerServlet.java:31)提示错误行:serviceL = topicService.findServiceTopic();
请教、如解决立马给分、急、在线等!!
int serviceI = 0; //创建迭加变量
while(serviceIt.hasNext()){
Topic serviceT = (Topic) serviceIt.next(); //迭代获取话题
Path.addElement("hot").setText(serviceT.getTotitle()); //添加子节点
serviceI++; //累加迭加变量
if(serviceI == 5){ //当累加变量加5时(获取5位时)、停止迭代
break;
}
}Servlet代码: @Autowired
@Qualifier("topicServiceIMPL")
private TopicService topicService; // 调用topicService
public static List<Topic> serviceL;
public void init() throws ServletException {
if(serviceL != null){
serviceL.clear();
}
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
System.out.println("存前:" + serviceL);
serviceL = topicService.findServiceTopic();
System.out.println("存后:" + serviceL);
}
}, 0, 10000);
}Service代码: public List<Topic> findServiceTopic() {;
return topicDaoIMPL.findServiceTopic();
}需实现功能:
当服务器启动则进行查询数据库存值、在规定时间内取值时不进行计算取值、到规定时间时系统自动再次进行查询存值报错:Exception in thread "Timer-2" java.lang.NullPointerException
at com.gys.util.TimerServlet$1.run(TimerServlet.java:31)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
at com.gys.util.TimerServlet$1.run(TimerServlet.java:31)提示错误行:serviceL = topicService.findServiceTopic();
请教、如解决立马给分、急、在线等!!
解决方案 »
- xdoclet 关于生成hibernate配置的简单问题
- 请教ant达人
- actionform 的 validate问题。
- org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
- DWR函数返回的值,可以传递到Form表单中?
- 关于复制网页的剪贴板信息问题
- 开始学EJB,各位前辈能否为兴致勃勃的我推荐基本酷书?
- 使用用RATIONAL ROSE,设计好一个类后, 怎样生成某种编程语言(比如是JAVA)的对应程序代码呢?
- 救命啊,关于生成xml
- 关于在session bean中调用entity bean的问题
- 想请教各位一个问题,关于ejb方面的
- 关于httpServlet的问题
topicDaoIMPL.findServiceTopic();topoicDaoIMPL 在哪里啊 , 注入否