我正在使用Weblogic 10.3,Spring 2.0,Oracle 11g。当尝试使用'threadpoolexecutor'未来任务(async resp)时,我在等待异步响应时遇到以下异常,其中由线程池执行程序执行的bean是'prototype'
注意:当我使用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
也试过threadpoolexecutor
,没有运气。
答案 0 :(得分:1)
问题不在于来自java.util.concurrent或weblogic的任何内容。 weblogic告诉你的是,其中一个已注册的线程已经等待超过10分钟,get()
才能返回。
那为什么不归还?这是因为您提交的Callable
尚未返回。您应该检查您提交给执行者的可调用对象,并找出仍然在call()
方法中的原因。
例如,如果我写了类似
的内容Weblogic-Thread-1
Future f= e.submit(new Callable(){
public Object call(){
Thread.sleep(700000);
return null;
}
});
Weblogic-Thread-2
f.get(); //will sit here and suspend for 700 seconds
因此,您需要了解您提交的任务尚未完成的原因。