1 2 Previous Next 20 Replies Latest reply on Mar 30, 2011 6:37 AM by km wen

    Exception handling in JBPM4 ?

    Atul Joshi Newbie
      Exception handling in JBPM4 ?
      An unhandled runtime exception occurs, I am not able to see any history of the process because everything is rolled back. What is the recommended way to achieve this ? Please find the attached example which i am trying , and provide me the solution for the same.
      In the attached example, On the activity A4 I explicitly throw exception, But the other activities are successfully completed after submitted the process. Successfully completed activities history should be updated in the JBPM4 history table, but JBPM4 engine will rollback everything, not keeping the track of the completed activities, Please provide me the solution to commit the successfully completed activities history in history table of the JBPM i.e





        • 1. Re: Exception handling in JBPM4 ?
          Santanu Saraswati Novice

          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.

          • 2. Re: Exception handling in JBPM4 ?
            Hernan Rodriguez Newbie

            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.

            • 3. Re: Exception handling in JBPM4 ?
              Atul Joshi Newbie
              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
              • 4. Re: Exception handling in JBPM4 ?
                Yogita Bartake Newbie
                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!!!
                • 5. Re: Exception handling in JBPM4 ?
                  Ronald van Kuijk Master
                  Transaction demarcation is done by using the async attribute on nodes. See the documentation for this.
                  • 6. Re: Exception handling in JBPM4 ?
                    Yogita Bartake Newbie

                    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?

                    • 7. Re: Exception handling in JBPM4 ?
                      Maciej Swiderski Master

                      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?




                      • 8. Re: Exception handling in JBPM4 ?
                        Ronald van Kuijk Master
                        new questions in new topics please
                        • 9. Re: Exception handling in JBPM4 ?
                          Ronald van Kuijk Master
                          And these fundamental questions even more so (new topic)
                          • 10. Re: Exception handling in JBPM4 ?
                            Atul Joshi Newbie
                            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 ?
                            • 11. Re: Exception handling in JBPM4 ?
                              Maciej Swiderski Master

                              Agree, sorry for that. New discussion started - How to handle rollback due to runtime errors


                              • 12. Re: Exception handling in JBPM4 ?
                                Yogita Bartake Newbie

                                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!!!!



                                • 13. Re: Exception handling in JBPM4 ?
                                  Atul Joshi Newbie
                                  I have changed the process design as follows.
                                  1. Instead of System Activity call Sub Process, name as "Sub_process_catch_Exception" ,
                                  2. In this sub process Instead of calling the system activity add Decision activity (Implement Business Logic in decision instead of SystemActiviy),
                                  3. If Decision activity executed successfully then
                                  Sub Process will end Else Forward control to next activity (i.e. State Node.)End if
                                  1. Trigger Wait (State Node) activity after resolving the exception by using the execution Id of the activity
                                  Please refer the attached code. Advantage:
                                  1. 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,
                                  1. I have almost completed my workflow design, if I want to implement Exception Handling I need to change my design from scratch,
                                  Suggest me if i can do better to handle exceptions in JBPM4?
                                  • 14. Re: Exception handling in JBPM4 ?
                                    Yogita Bartake Newbie

                                    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 =

                                    null ;

                                    processEngine =

                                    new Configuration().setResource("jbpm.cfg.xml").getProcessEngine();




                                    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.



                                    1 2 Previous Next