JBoss Community

Re: Commit transaction after each service task?

created by Richard Evans in jBPM - View the full discussion

Hello Rahul. Yes, I did implement this strategy (or something very similar using a thread pool). I have often run into problems with the persistence context but have found everything works if I ensure there is no running transaction when I enter jbpm code.

 

 

In a common superclass of all handlers...

 

@Override

public final void executeWorkItem(WorkItem workItem, WorkItemManager manager) {

    WorkHandlerRunner task = new WorkHandlerRunner(kSession, workItem, this);

    synchronized (threadPoolTaskExecutor) {

        threadPoolTaskExecutor.execute(task);

    }

}

 

 

In WorkHandlerRunner...

@Override

public void run() {

    WorkItemManager manager = kSession.getWorkItemManager();

    Map<String, Object> result = null;

 

 

    try {

        result = doRun(manager);

    } catch (Exception e) {

        ...

    }

    manager.completeWorkItem(workItem.getId(), result);

}

 

 

// Do my stuff and commit.

@Transactional

private Map<String, Object> doRun(WorkItemManager manager) throws Exception {

    return handler.doExecuteWorkItem(workItem, manager);

}

Reply to this message by going to Community

Start a new discussion in jBPM at Community