[jbpm-commits] JBoss JBPM SVN: r2406 - jbpm3/branches/aguizar/modules/core/src/main/java/org/jbpm/job/executor.

do-not-reply at jboss.org do-not-reply at jboss.org
Sat Sep 27 02:37:02 EDT 2008


Author: alex.guizar at jboss.com
Date: 2008-09-27 02:37:01 -0400 (Sat, 27 Sep 2008)
New Revision: 2406

Modified:
   jbpm3/branches/aguizar/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java
Log:
have job executor thread rollback on persistence exception

Modified: jbpm3/branches/aguizar/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java
===================================================================
--- jbpm3/branches/aguizar/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java	2008-09-27 05:25:27 UTC (rev 2405)
+++ jbpm3/branches/aguizar/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java	2008-09-27 06:37:01 UTC (rev 2406)
@@ -166,17 +166,18 @@
         if (job.execute(jbpmContext)) {
           jobSession.deleteJob(job);
         }
-      } catch (HibernateException e) {
-        log.debug("exception while executing " + job, e);
-        // allowing a transaction to proceed after a persistence exception is unsafe
-        // TODO rollback on *any* runtime exception?
-        jbpmContext.setRollbackOnly();
       } catch (Exception e) {
         log.debug("exception while executing " + job, e);
-        StringWriter memoryWriter = new StringWriter();
-        e.printStackTrace(new PrintWriter(memoryWriter));
-        job.setException(memoryWriter.toString());
-        job.setRetries(job.getRetries()-1);
+        if (isPersistenceException(e)) {
+          StringWriter memoryWriter = new StringWriter();
+          e.printStackTrace(new PrintWriter(memoryWriter));
+          job.setException(memoryWriter.toString());
+          job.setRetries(job.getRetries()-1);          
+        }
+        else {
+          // allowing a transaction to proceed after a persistence exception is unsafe
+          jbpmContext.setRollbackOnly();
+        }
       }
       
       // if this job is locked too long
@@ -188,7 +189,7 @@
       try {
         jbpmContext.close();
       } catch (JbpmPersistenceException e) {
-        // if this is a stale object exception, keep it quiet
+        // if this is a stale state exception, keep it quiet
         if (Services.isCausedByStaleState(e)) {
           log.debug("optimistic locking failed, couldn't complete job "+job);
         } else {
@@ -197,6 +198,16 @@
       }
     }
   }
+
+  private static boolean isPersistenceException(Throwable throwable) {
+    do {
+      if (throwable instanceof HibernateException)
+        return true;
+      throwable = throwable.getCause();
+    } while (throwable != null);
+    return false;
+  }
+
   protected Date getNextDueDate() {
     Date nextDueDate = null;
     JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();




More information about the jbpm-commits mailing list