0 Replies Latest reply on Jun 20, 2014 6:58 AM by Laura delli Paoli

    JBAS010152: APPLICATION ERROR: transaction still active in request with status 0 on creating thread in Custom WorkItemHandler

    Laura delli Paoli Master

      Hello everybody,

      I'm trying to simulate a jBPM workflow handler for a long running task (In truth this task can last some seconds or some hours).

      In jBPM 5.4 I handled this issue launching my job in a separate thread and completing the workItem after resuming the KnowledgeSession.

      Now I'm migrating to jBPM6 and I'd love to know REST API and let jBPM manage its sessions, so I implemented my executeWorkItem method in a class implementing WorkItemHandler interface:

       

      public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {

        final long pid = workItem.getProcessInstanceId();

        trace.info("this is RunTaskHandler for process " + pid);

        final long wiId = workItem.getId();

        trace.info("this is the wiId " + wiId);

       

        new Thread(new Runnable() {

        public void run() {

        int procRes = -1;

        Map<String, Object> result = new HashMap<String, Object>();

        try {

        trace.info("I am simulating a LongRunning Task!!");

        result.put("RunTaskExitValue", new Integer(0));

        Thread.sleep(100000);

        JBpmRemoteServices.getInstance().completeWorkItemViaRestAPI(wiId, result);

        trace.info("thread completed");

        } catch (Exception e) {

        throw new RuntimeException("Error encountered while invoking ws operation asynchronously", e);

        }

        }

        }).start();

        }

       

       

      and completeworkitemViaRESTAPI:

      public void completeWorkItemViaRestAPI(long workItemId, Map<String, Object> results) throws MalformedURLException {

        KieSession ksession = engine.getKieSession();

        trace.info("KieSession created!");

        WorkItemManager workItemManager = ksession.getWorkItemManager();

        trace.info("WorkItemManager created!");

        workItemManager.completeWorkItem(workItemId, results);

        }

       

      On running my process from the console I get the following trace:

       

      18:50:43,754 INFO  [*****] (http-10.21.30.73-10.21.30.73-8080-2) this is LogTaskHandler for process 230

      18:50:43,794 INFO  [stdout] (http-10.21.30.73-10.21.30.73-8080-2) Preparing parameters

      18:50:43,808 INFO  [*****] (http-10.21.30.73-10.21.30.73-8080-2) this is RunTaskHandler for process 230

      18:50:43,835 INFO  [******] (http-10.21.30.73-10.21.30.73-8080-2) this is the wiId 388

      18:50:43,877 ERROR [org.jboss.as.txn] (http-10.21.30.73-10.21.30.73-8080-2) JBAS010152: APPLICATION ERROR: transaction still active in request with status 0

       

      Can anyone help me?