1

I am using Weblogic 10.3, Spring 2.0,Oracle 11g. When trying to use the 'threadpoolexecutor' future task (async resp), I am getting the following exception in waiting for asynchronous response where as the bean executed by thread pool executor is 'prototype'

Note: when I am using Spring's ClassPathXmlApplicationContext to get the bean I am not getting the exception, which is not a preferred way to get beans as it loads all the beans again.

I have tried springContextAware ,ApplicationObjectSupport; those also didn't work for me.

 - 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)

The bean definition I have is

    <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];
                }

I have tried with lazy-init=true also on threadpoolexecutor, no luck.

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

1

The issue isn't with anything coming from java.util.concurrent or weblogic. What weblogic is telling you is that one of its registered threads has been waiting longer then 10 minutes for the get() to return.

So why hasn't it returned? That is because the Callable you submitted has not yet returned. You should check the callable you submit to the executor and find out why that is still in the call() method.

For instance, if I write something like

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 

So you need to see why the task you submitted has not yet completed.

John Vint
  • 39,695
  • 7
  • 78
  • 108
  • Hi @John , thanks for the response, the thing confusing me is if I use ApplicationContext ctx=new ClassPathXmlApplicationContext(filename); ctx.getBean(ptTaskExecutor) I am not getting delay in response , If I inject the bean or if I use the ApplicationContextAware or a 'static block to load the ctx once' I am getting timeout exception.I can't use ClassPathXmlApplicationContext as it impacts performance.DB logs are not showing any errors/exceptions.With bena injection business errors from db in response are in time only correct TX which need to get back with Oparams are failing – user2609566 Jul 24 '13 at 05:02
  • Try running and `kill 3` the process. It will generate a thread-dump that may help. Otherwise it's too difficult to say what the problem is. – John Vint Jul 24 '13 at 11:15
  • because of the time limits instead of a bean I have used a new static Threadpool executor class in java, seems the issue is mostly between threadpoolexecutor and SpringBeans2.0 – user2609566 Jul 29 '13 at 04:56
  • The latest findout is if both ThreadPoolExecutor and it's submitTask (ie xTask) are of the same scope(ie prototype), the code is working fine, else it is failing. If ithe executor is prototype at somepoint no of threads creation and its control might be difficult or overhead for performance. – user2609566 Jul 29 '13 at 15:56
  • ThreadPoolExecutor must be singlton, this is not only Executor, this is also ThreadFactory. task should be Runnable or Callable. the error message is very clear, your task is block. i don't know why block, may be thread's coresize is so small, may be your task is not correct. in spring 4.0, you can use Spring enhance concurrent package to do with this. – zg_spring Nov 14 '14 at 08:47