-
1. Re: Threads in WorkItemHandler implementations with Persistence mode enabled
akoskm Jul 1, 2014 9:28 AM (in response to akoskm)Looking at the documentation:
Chapter 24. Concurrency and asynchronous execution
my solution to create a separate thread to do the "heavy lifting" and complete the work item from there seems legit, what I'm missing?
-
2. Re: Threads in WorkItemHandler implementations with Persistence mode enabled
swiderski.maciej Jul 4, 2014 2:25 AM (in response to akoskm)1 of 1 people found this helpfulbest is to actually pass the runtime manager to your background thread instead of work item manager that will be deactivated after transaction completes. So ensure you will have runtime manager in your work item handler and then pass it into the thread so when the job is done you can get RuntimeEngine out of it and then ksession and finally work item manager to complete the work.
Take a look at jbpm executor as well that provides all the async features you most likely need without any additional coding.
HTH
-
3. Re: Re: Threads in WorkItemHandler implementations with Persistence mode enabled
akoskm Jul 4, 2014 3:43 AM (in response to swiderski.maciej)Thanks for your answer.
This was actually my error. I have a couple of unit tests for my jBPM persistence modules.
I figured out that after starting the process in the unit test, my handler actually starts to work asynchronously, but the unit test finishes before the handler is completed.
This of course shuts down the main thread which was started by the unit test itself:
@Test public void humanTaskTest() throws Exception { RuntimeManager manager = getRuntimeManager("process/humantask/HumanTask.bpmn"); RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get()); KieSession ksession = runtime.getKieSession(); ProcessInstance proc = ksession.startProcess("com.sample.humantask", null); // <-- handler is invoked and started the background thread but the unit test exits after this line }
I've achieved the correct behavior by putting a Thread.sleep(20000) after startProcess.
My async handler had enough time to finish its job and everything worked as expected.