我正在使用 Weblogic 10.3、Spring 2.0、Oracle 11g。当尝试使用“threadpoolexecutor”未来任务(异步响应)时,我在等待异步响应时遇到以下异常,因为线程池执行程序执行的 bean 是“原型”
注意:当我使用 Spring 的 ClassPathXmlApplicationContext 来获取 bean 时,我没有收到异常,这不是获取 bean 的首选方式,因为它会再次加载所有 bean。
我试过 springContextAware ,ApplicationObjectSupport; 那些对我也不起作用。
- Error:
]", which is more than the configured time (StuckThreadMaxTime) of "600" seconds. Stack trace:
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:811)
java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:969)
java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1281)
java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:218)
我的bean定义是
<bean id="PtTaskExecutor"
class="java.util.concurrent.ThreadPoolExecutor">
<constructor-arg index="0" value="1"/> <!-- corePoolSize -->
<constructor-arg index="1" value="3"/> <!-- maximumPoolSize -->
<constructor-arg index="2" type="long" value="180"/><!-- 3 minutes -->
<!-- keepAliveTime -->
<constructor-arg index="3" type="java.util.concurrent.TimeUnit">
<!-- the time unit for the keepAliveTime argument -->
<util:constant static-field="java.util.concurrent.TimeUnit.SECONDS"/>
</constructor-arg>
<constructor-arg index="4" type="java.util.concurrent.BlockingQueue">
<!-- the queue for holding tasks before they are executed -->
<bean name="LinkedBlockingQueue" class="java.util.concurrent.LinkedBlockingQueue">
<constructor-arg index="0" type="int" value="3"/> <!-- capacity -->
</bean>
</constructor-arg>
<constructor-arg index="5" type="java.util.concurrent.RejectedExecutionHandler">
<!--Execute with caller threads if queue is full -->
<bean class="java.util.concurrent.ThreadPoolExecutor$CallerRunsPolicy"/>
</constructor-arg>
</bean>
<bean id="xTask" class="***.****.*.*.*.*.XTask" scope="prototype">
<property name="XDao" ref="XDao" />
<property name="transactionTemplate" ref="transactionTemplate"/>
</bean>
-----The code part
Future<YResponseBean[]> responseArr = pTaskExecutor
.submit(xTask);
responseMap.put(i, responseArr);
then the error is from here
for (Integer i : keySet) {
// Waits for the thread response
responses[i] = responseMap.get(i).get()[0];
}
我也试过lazy-init=true
on threadpoolexecutor
,没有运气。