Announcement Announcement Module
Collapse
No announcement yet.
ThreadPoolExecutor within an action component Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ThreadPoolExecutor within an action component

    Hi folks,

    I am trying to run a callable thread using a ScheduledThreadPoolExecutor within a MultiAction component where the callable is submitted in one flow, and retrieved in a later flow. The callable is using a DAO which is session scoped.

    /*TODO: this exception is being generated in subsequent get().
    * java.util.concurrent.ExecutionException: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'scopedTarget.firmDao': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
    */
    public class FirmAcquire implements Callable<List<Adapter>> {
    private ComponentClientDao<Adapter> myDao;

    public FirmAcquire (ComponentClientDao<Adapter>
    initializedDao) {
    myDao = initializedDao;
    }

    @Override
    public List<Adapter> call() throws Exception {
    logger.debug("getting firm adapters");
    List<Adapter> allAdapters = myDao.getAllInstances();
    Collections.sort(allAdapters);
    logger.debug("got firm adatpers");
    return allAdapters;
    }

    }

    I submit the callable in one flow, and retrieve it in another, generating the exception which precedes the callable.

    @Autowired
    private ExecutorService sharedExecutor;

    @Resource(name="firmDao")
    private ComponentClientDao<Adapter> firmDao;
    //on init of flow.
    public void loadInitialContext(RequestContext context){
    List<String> firms = firmDao.getInstanceNames();

    Callable<List<Adapter>> c = new FirmAcquire (firmDao);

    //begin loading the firms since they take a long time.
    firmFut = sharedExecutor.submit(c);

    FirmAdapterForm form = new FirmAdapterForm();
    form.setOeFirmsList(curOeFirmsList);
    context.getConversationScope().put(TemplateConstan ts.OEFIRM_EDIT_FORM, form);
    }

    //later in the flow.
    public void loadFirm (RequestContext context) {
    List<Adapter> firmInfo = null;
    try {
    firmInfo = firmFut.get();
    } catch(InterruptedException ie) {
    logger.error("unable to acquire firm information " + ie);
    } catch(ExecutionException ee) {
    logger.error("unable to acquire firm information " + ee);
    }
    }

    <bean id="firmDao" class ="com.dao.firmDao"
    scope="session">
    <constructor-arg ref="tplCachingClientFactory" />
    ...
    </bean>
    <bean id="sharedExecutor"
    class="java.util.concurrent.ScheduledThreadPoolExe cutor"
    scope="session"
    init-method="prestartCoreThread">
    <aop:scoped-proxy proxy-target-class="false"/>
    <constructor-arg>
    <value>3</value>
    </constructor-arg>
    </bean>




    So, to the question; what is causing this exception? I had thought that the Dao was already inserted into the proxy on instantiation of the action. Can someone step me through the lifecycle event which is causing this?

    Thanks in advance,
    --
    Benson
Working...
X