Exception is strictly for exceptional conditions.. specially runtime exceptions. This has nothing to do with jBPM, this is a general practice for Java (and for most of other languages which has exception construct). You might like to refer to Effective Java, chapter 9.
Exception should not be used as a valid business case. If you think you can recover from an exception (and create history entries etc.) then you should catch and handle it gracefully. Committing some information on the event of an exception is dangerous and beats the purpose of transaction. I do not think will be supported in any way.
I have the same problem with Java Task nodes.
For example, I'm using the following model:
(java1, java2 and java 3 are Java Task. state1 is a State node)
When start the execution, this stop in "state1". Then, I resume the process instance. If "java3" throws an Exception the transaction is rolled back until "state1".
If "java1" and "java2" were successfully completed.. why are rolled back?
It's possible commit the transaction after each node?. This is possible with "Custom Nodes", but I need to do the same with Java Task nodes.
The source of the model is:
<?xml version="1.0" encoding="UTF-8"?>
<process key="test" name="test" xmlns="http://jbpm.org/4.2/jpdl">
<start g="19,19,48,48" name="start1">
<transition g="33,-7" name="to java1" to="state1"/>
<state g="60,71,92,52" name="state1">
<transition g="13,-29" name="to java1" to="java1"/>
<java class="cl.pred.cmh.bpm.events.controller.TraspasoController" g="136,140,92,52" method="test" name="java1" var="respuesta1">
<transition g="2,-17" name="to java2" to="java2"/>
<java class="cl.pred.cmh.bpm.events.controller.TraspasoController" g="281,281,92,52" method="test" name="java3" var="respuesta3">
<transition g="3,-26" name="to end1" to="end1"/>
<java class="cl.pred.cmh.bpm.events.controller.TraspasoController" g="203,207,92,52" method="test" name="java2">
<transition g="10,-21" name="to java3" to="java3"/>
<end g="372,332,48,48" name="end1"/>
Any suggestion will be greatly appreciated.
How you commit the transaction after each node by using the Custom Nodes in custom class ? Could you please send us example on the same. Thanks in advance
I am facing a similar problem. When an error occurs I want the user to retry the activity. For that I need to commit all the previously succesfully completed activities. Please Help!!!
Transaction demarcation is done by using the async attribute on nodes. See the documentation for this.
Thanks Ronald .
I have another related query.
I am trying to suspend the exeution when I get an error and later resume the same. But the only way I could find is by using the ExecutionImpl's suspend/resume method.
How can I achieve the same using services?
What about following scenario:
- there are 4 nodes (regardless of type) that are executed as one transaction.
- some of the nodes modify external systems via different protocols
- no exceptions are thrown from nodes
- runtime exception is thrown due to some db issues
Transaction will be rolled back but changes made to external system are not rolled back since they were not part of the transcation (for example web service call).
Have you put any thoughts into that? I was wondering if some sort of compensation mechanism could be introduced to the execution where nodes that take part in transaction can inform runtime engine what to invoke in case of roll backs. This could give kind of undo operation for already finished nodes and should not cause any problems when process will go thru them again.
What's your opinion about it? Does it sound reasonable?
new questions in new topics please
And these fundamental questions even more so (new topic)
I used async attribute for the activities in the process , This attributes help us to commit the successfully completed activities , but how can I re execute the activity which haveing the exception, because jbpm4 will rollback the execution id of the activity which having the exception, How can I achieve the same ?
Atul I am trying the same thing in the following manner:
I used async for the activities. When an exception occurs, in the catch block I am suspending the execution n later resuming it. With this the id that u mentioned does not get lost.
But with this I am not able to take the execution ahead. This I have mentioned in another thread. Is there any way to execute that activity again? Please Help!!!!
I have changed the process design as follows.
- Instead of System Activity call Sub Process, name as "Sub_process_catch_Exception" ,
- In this sub process Instead of calling the system activity add Decision activity (Implement Business Logic in decision instead of SystemActiviy),
- If Decision activity executed successfully then
- Trigger Wait (State Node) activity after resolving the exception by using the execution Id of the activity
- I am able to implement Retry, Skip, Max No. of Retries and timeout for all JAVA activities present in my Workflow design, using this common solution,
- I have almost completed my workflow design, if I want to implement Exception Handling I need to change my design from scratch,
JPDL FILES.zip 12.5 KB
Thats a good solution but a bit cumbersome Atul.
I am doing retry in the following manner and its working fine.
void retry(String id)
ProcessEngine processEngine =
ManagementService managementService = processEngine.getManagementService();
Job job = managementService.createJobQuery().processInstanceId(id).uniqueResult();
With this u wont have to redesign your Workflow. but m still stuck with skip. I have started a new thread for this.