4 Replies Latest reply on Nov 25, 2008 12:04 PM by Ronald van Kuijk

    Problems with GraphSession.deleteProcessInstance()

    Michael Holtzman Newbie


      We need to periodically purge process instances that have ended before a certain data. There may be hundreds or thousands of instances that need to be cleaned up. The performance is very poor ... about 8 - 10 seconds PER INSTANCE.

      Looking at the code (jBPM 3.1.2) I notice two things:

      1 - task instances are not deleted (the delete query is not executed, which is just as well because the preceding query, findTaskInstanceIdsForProcessInstances, does not actually return a list of ids so it would fail anyway).:

       if (includeTasks) {
       query = session.getNamedQuery("GraphSession.findTaskInstanceIdsForProcessInstance");
       query.setEntity("processInstance", processInstance);
       List<?> taskInstanceIds = query.list();
       query = session.getNamedQuery("GraphSession.deleteTaskInstancesById");
       query.setParameterList("taskInstanceIds", taskInstanceIds);

      Fixing the findTaskInstanceIdsForProcessInstance query and inserting query.executeUpdate() results in constraint errors in the database.

      2 - Deleting the process logs are done one log entry at a time
       // delete the logs for all the process instance's tokens
       if ( (tokens!=null)
       && (!tokens.isEmpty())
       ) {
       query = session.getNamedQuery("GraphSession.selectLogsForTokens");
       query.setParameterList("tokens", tokens);
       List<?> logs = query.list();
       iter = logs.iterator();
       while (iter.hasNext()) {

      I'm guessing this is taking most of the execution time .... is there a way to batch delete these logs?