SSH框架多线程问题,求助!

GaryTing2010 2012-03-20 10:46:56
在action里面开一个线程,然后在这个线程中创建线程池,往线程池里添加N个线程,这些线程是有链接数据库的操作的,在运行的时候,凡是spring注入的变量都是空,报空指针错误,求助怎么解决这个问题。
...全文
593 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
lanjf2000 2013-07-09
  • 打赏
  • 举报
回复
期待中,我也遇上同样的问题,spring的taskExecutor启用线程池,可是操作数据库总是获取不到session
shiyongna 2013-05-24
  • 打赏
  • 举报
回复
问题解决没啊
聽媽媽De話 2013-04-24
  • 打赏
  • 举报
回复
同样求助啊!!!
ylovep 2012-03-20
  • 打赏
  • 举报
回复
围观一下 表示非常有意思
xieshengjun2009 2012-03-20
  • 打赏
  • 举报
回复
有意思。。。!顶顶顶!
GaryTing2010 2012-03-20
  • 打赏
  • 举报
回复
其他的注入都是正常的,只有线程里面的注入有问题,这个spring可以配置吗?
kouyiSC 2012-03-20
  • 打赏
  • 举报
回复
说明注入有问题咯。。。检查配置咯。。。
GaryTing2010 2012-03-20
  • 打赏
  • 举报
回复

@Override
public String execute() throws Exception {
saveOnSelfModels();

StartThread sendRun = new StartThread();
sendRun.setOnShelfMap(onShelfMap);
sendRun.start();

return SUCCESS;
}


这个是action里面启动线程的的一步:

private ExecutorService executorService;
public StartThread(){
initExecuteService();
}
public void initExecuteService(){
executorService = Executors.newFixedThreadPool(Constants.THREAD_POOL_SIZE);
}
@Override
public void run() {
//first send
List<SendEmergencyThread> sendList = new ArrayList<SendEmergencyThread>();
Set<OnShelf> key = onShelfMap.keySet();
for(OnShelf onShelf : key){
OnShelfBat onShelfBat = onShelfMap.get(onShelf);
SendEmergencyThread newSendThread = new SendEmergencyThread(onShelf, onShelfBat, false);
executorService.execute(newSendThread);
sendList.add(newSendThread);
}
shutDown();
//thread wait
try{
boolean loop = true;
do{
loop = !executorService.awaitTermination(2, TimeUnit.SECONDS);
}while (loop);
} catch (Exception e) {
e.printStackTrace();
}
}

这是初始化线程池的线程,然后SendEmergencyThread 是也是一个线程类,在SendEmergencyThread里面会有操作数据库的步骤,但是在这里spring就不能注入了,会报空指针错误。
ss36290109 2012-03-20
  • 打赏
  • 举报
回复
代码看看咯,我也写过类似这种 不过可以取到数据压

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧