7 Replies Latest reply on Jul 13, 2011 10:36 PM by trh3037

    How to finish the processInstance

    trh3037

      I have finished all tasks for the proceeInstance , why the state of processInstance is still '1' ?

       

      Is not what I had to deal with other cases?

       

      My English is not good ,excuse me

       

      Here is my code:

       

      BlockingTaskOperationResponseHandler responseHandler = new BlockingTaskOperationResponseHandler();

                          client.start(taskId, userId, responseHandler);

                          responseHandler.waitTillDone(5000);

                          // Thread.sleep(10000);

                          responseHandler = new BlockingTaskOperationResponseHandler();

                          ContentData contentData = null;

                          if (data != null) {

                                    ByteArrayOutputStream bos = new ByteArrayOutputStream();

                                    ObjectOutputStream out;

                                    try {

                                              out = new ObjectOutputStream(bos);

                                              out.writeObject(data);

                                              out.close();

                                              contentData = new ContentData();

                                              contentData.setContent(bos.toByteArray());

                                              contentData.setAccessType(AccessType.Inline);

                                    } catch (IOException e) {

                                              e.printStackTrace();

                                    }

                          }

                          client.complete(taskId, userId, contentData, responseHandler);

                          responseHandler.waitTillDone(5000);

        • 1. Re: How to finish the processInstance
          krisverlaenen

          It would be useful if you could also paste your process, to figure out what else the process is doing.

           

          Kris

          • 2. Re: How to finish the processInstance
            trh3037

            this is my codes:

            未命名.jpg

            未命名.jpg

             

             

            未命名.jpg

            • 3. Re: How to finish the processInstance
              krisverlaenen

              This all seems to be normal.

              Why do you think that the processInstance is still active in this case?

              If you do ksession.getProcessInstance(id) after completing the user task, do you get a process instance in state active? Or null?

               

              Or are you looking at the processInstance variable in this case?  As the processInstance variable in your code is a snapshot of the state of the process instance after starting it.  Note that this process instance is disconnected, meaning that it will not update when the state of the process instance in the engine is updated.  To get an updated state, you need to do ksession.getProcessInstance(id) again.  In this case, this should return null, as the process instance has completed.

               

              Kris

              • 4. Re: How to finish the processInstance
                trh3037

                Thanks Kris .

                 

                I try to use the following case, it automatically ends, and remove the process record in the database.

                In my understanding, when the process is finished, it will  be deleted automatically:

                 

                未命名.jpg

                未命名.jpg

                 

                 

                When i finish all the tasks for the process instance and i found that the state of the instance is still '1' in the database

                 

                未命名.jpg

                • 5. Re: How to finish the processInstance
                  trh3037

                  And now, I had another problem occurred .

                   

                  When I finish the first task, the process can not start the second task

                   

                  With the following pictures may be more clearer:

                   

                  未命名.jpg

                  未命名.jpg

                   

                  As far as I know, when the process is started, it will call WSHumanTaskHandler.executeWorkItem()

                   

                  Meanwhile, when the task is ended, it will also to call WSHumanTaskHandler.executeWorkItem()

                   

                  But the truth is it is not called

                   

                  here is my codes:

                   

                  /**

                             * start the process

                             *

                             * @param event

                             * @throws InterruptedException

                             */

                            public void onTest1(Event event) throws InterruptedException {

                                      try {

                                                StatefulKnowledgeSession ksession = JbpmAPIUtil

                                                                    .createKnowledgeSession("HelloProcess.bpmn");

                                                // , "SampleHumanTaskFormVariables.bpmn"

                                                logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(

                                                                    ksession, "testlog", 1000);

                                                ksession.getWorkItemManager().registerWorkItemHandler("Human Task",

                                                                    new CommandBasedWSHumanTaskHandler(ksession));

                                                dblogger = new JPAWorkingMemoryDbLogger(ksession);

                                                Map<String, Object> params = new HashMap<String, Object>();

                                                params.put("employee", "krisv");

                                                ksession.startProcess("HelloProcess");

                                                ksession.fireAllRules();

                                        } catch (Throwable t) {

                                                t.printStackTrace();

                                      }

                            }

                   

                   

                            /**

                             * finish the task

                             *

                             * @param event

                             * @throws InterruptedException

                             */

                            public void onTest2(Event event) throws InterruptedException {

                                      try {

                                                List<TaskSummary> tasks = JbpmAPIUtil

                                                                    .getTasksAssignedAsPotentialOwner("krisv");

                                                //Map data = new HashMap();

                                                for (TaskSummary taskSummary : tasks) {

                                                          System.out.println(taskSummary.getId() + " : "

                                                                              + taskSummary.getName());

                                                          // data.put("priority", "High");

                                                          // data.put("modelNumber", "1234");

                                                          // data.put("quantity", "225");

                                                          JbpmAPIUtil.completeTask(taskSummary.getId(), null, "krisv");

                                                }

                                                dblogger.dispose();

                                                logger.close();

                                      } catch (Throwable t) {

                                                t.printStackTrace();

                                      }

                            }

                  未命名.jpg

                  • 6. Re: How to finish the processInstance
                    jcharnet

                    I have the same problem.


                    I'm finishing my human task, with the taskClient API, calling start and complete on the human task. But my next task, (after the human task) never gets called.

                     

                    Do I need to do something else in my code ?

                     

                     

                    Thanks a lot.

                     

                    John

                    • 7. Re: How to finish the processInstance
                      trh3037

                      I still have not resolved the problem,what about you?