-
1. Re: Asynchronous service tasks and transactions
swiderski.maciej Aug 24, 2012 6:31 AM (in response to rahulamt)when instantiating your handler ensure that it will get access to knowledge session:
new YouHandlerImpl(ksession)
and then inside you handler, when it's done with processing use session to complete work item:
session.getWorkItemManager().completeWorkItem(workItemId, result);
HTH
-
2. Re: Asynchronous service tasks and transactions
rahulamt Aug 24, 2012 8:08 AM (in response to swiderski.maciej)Hi,
I doing it the same way but not directly. I am not registering my handler with kession. But the completeWorkItem(workItemId, result) i am calling on the same session. The call to this method is not inside the handler but inside an ejb that is called from the new thread that i am calling.
My workItemHandler is as follows:
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
final String operation = (String) workItem.getParameter("Operation");
final WorkItem internalWorkItem = workItem;
final WorkItemManager internalWorkItemManager = manager;
new Thread(new Runnable()
{
public void run()
{
Map<String, Object> inParams = internalWorkItem.getParameters();
inParams.put("workItemId",Long.valueOf(internalWorkItem.getId()));
inputParams.add((Serializable)inParams);
try
{
results = EJBCallLookUP.call(operation, inputParams);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}).start();
}
in the EJBCallLookUP.call I am looking up the ejb for the operation and calling the method with operation name. Inside that operation i am calling the completeWorkItem(...) with the session.
-
3. Re: Asynchronous service tasks and transactions
swiderski.maciej Aug 24, 2012 8:10 AM (in response to rahulamt)and how do you pass session to the ejb? Do you get any errors or what is the problem?
-
4. Re: Asynchronous service tasks and transactions
rahulamt Aug 24, 2012 9:10 AM (in response to swiderski.maciej)I am saving sessions in a static variables and retrieving sessions from those static variables inside ebj. The error is even if I say the completeWorkItem(..) inside ejb or outside it, but always in a separate thread, the persistence context is not flushed. Essentially the workiteminfo entry is not removed for that workitem and nodeinstancelog and processinstancelog tables are also not updated. So there is inconsistency in the process state. But if i perform a new operation( any operation that will do some database transaction on jbpm database) like starting new process instance the persistence context is flushed.
-
5. Re: Asynchronous service tasks and transactions
swiderski.maciej Aug 24, 2012 9:50 AM (in response to rahulamt)1 of 1 people found this helpfulthen it looks like transaction issue, transaction is not committed properly so entity manager is not flushed as I believe flush type is set to commit. Is you ejb CMT or BMT?
-
6. Re: Asynchronous service tasks and transactions
rahulamt Aug 24, 2012 10:01 AM (in response to swiderski.maciej)ebj uses CMT. Sometimes transactions are not commited properly, but most of the times those are commited properly.
-
7. Re: Asynchronous service tasks and transactions
rahulamt Aug 27, 2012 6:36 AM (in response to swiderski.maciej)Hi Maciej,
the transactions are getting commited as far as application database transactions are concerned. I tried updating application database (this is different from the jBPM database) inside the EJB being called in a new thread. The updates to the that application database are getting commited properly. But the jBPM database is not updated. Is it the issue with hibernate or jBPM?
Please help!!
-
8. Re: Asynchronous service tasks and transactions
rahulamt Aug 28, 2012 9:31 AM (in response to swiderski.maciej)One more update I would like to inform. If I have deployed my application, and then I am debugging it in eclipse using remote debugging then everything works fine but once i turn off eclipse remote debugging and run it normally then I am stuck at the same point. What could be the reason for this strange behaviour?