【发布时间】:2009-12-14 03:04:16
【问题描述】:
我的服务层方法是事务性的,当我使用 ExecutorService 并将任务提交给线程时,我无法将 servicelayer 作为参数传递给每个线程,因为我得到了错误
Dec 14, 2009 10:40:18 AM com.companyx.applicationtest.applicationtestcompanyx.services.threadtestRunnable run
SEVERE: null
org.hibernate.HibernateException: No Hibernate Session bound to thread, and conf
iguration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.SpringSessionContext.currentSessio
n(SpringSessionContext.java:63)
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactor
yImpl.java:542)
我的服务层
ExecutorService executor = Executors.newFixedThreadPool(10);
for (final Object item : CollectionsTest{
executor.submit(new threadtestRunnable((Long)item,collectionAfterfiltered,this)); //'this' is service layer
}
- 我应该像这样将服务层传递给每个线程吗?
- 什么是正确的方法,我需要每个线程调用服务层中的方法? (我用的是弹簧)
【问题讨论】:
-
我不熟悉框架,但是,在多个线程中运行事务是否有意义?通常,事务是预定义的操作序列。如果您确实需要在事务中进行并行计算,您可以在工作线程中运行它们,但让它们将结果报告回您将它们提交到数据库的事务线程。
-
找人评论这个..事务应该在多个线程中吗?
标签: java spring multithreading