Repository: syncope
Updated Branches:
  refs/heads/1_2_X fed10a7a7 -> bdb3257c8


[SYNCOPE-660]Forcing interrupt for heavy tasks - minor improvement


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/bdb3257c
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/bdb3257c
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/bdb3257c

Branch: refs/heads/1_2_X
Commit: bdb3257c8f227716fe52d950aa6626e9bab84478
Parents: fed10a7
Author: giacomolm <giacom...@hotmail.it>
Authored: Mon Jun 22 16:14:10 2015 +0200
Committer: giacomolm <giacom...@hotmail.it>
Committed: Mon Jun 22 16:14:10 2015 +0200

----------------------------------------------------------------------
 .../syncope/core/quartz/AbstractTaskJob.java    | 29 +++++++++-----------
 1 file changed, 13 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/bdb3257c/core/src/main/java/org/apache/syncope/core/quartz/AbstractTaskJob.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/syncope/core/quartz/AbstractTaskJob.java 
b/core/src/main/java/org/apache/syncope/core/quartz/AbstractTaskJob.java
index 52615ae..2fcef9e 100644
--- a/core/src/main/java/org/apache/syncope/core/quartz/AbstractTaskJob.java
+++ b/core/src/main/java/org/apache/syncope/core/quartz/AbstractTaskJob.java
@@ -18,11 +18,8 @@
  */
 package org.apache.syncope.core.quartz;
 
-import java.text.SimpleDateFormat;
 import java.util.Date;
-import java.util.Locale;
 import java.util.concurrent.atomic.AtomicReference;
-import org.apache.syncope.common.SyncopeConstants;
 import org.apache.syncope.common.types.AuditElements;
 import org.apache.syncope.common.types.AuditElements.Result;
 import org.apache.syncope.core.audit.AuditManager;
@@ -32,6 +29,7 @@ import org.apache.syncope.core.persistence.beans.TaskExec;
 import org.apache.syncope.core.persistence.dao.ConfDAO;
 import org.apache.syncope.core.persistence.dao.TaskDAO;
 import org.apache.syncope.core.persistence.dao.TaskExecDAO;
+import org.apache.syncope.core.util.DataFormat;
 import org.apache.syncope.core.util.ExceptionUtil;
 import org.quartz.DisallowConcurrentExecution;
 import org.quartz.JobExecutionContext;
@@ -197,20 +195,19 @@ public abstract class AbstractTaskJob implements TaskJob {
     @Override
     public void interrupt() throws UnableToInterruptJobException {
         Thread thread = this.runningThread.getAndSet(null);
-        if (thread != null) {
-            LOG.info("Interrupting job time {} ", (new 
SimpleDateFormat(SyncopeConstants.DEFAULT_DATE_PATTERN, Locale.
-                    getDefault())).format(new Date()));
-            thread.interrupt();
-            if (thread.isAlive()) {                
-                long maxRetry = confDAO.find("tasks.interruptMaxRetries", 
"0").getValues().get(0).getLongValue();
-                for (int i = 0; i <= maxRetry && thread.isAlive(); i++) {
-                    thread.interrupt();
-                }
-                //if the thread is still alive, it should be available in the 
next stop
-                if(thread.isAlive()) this.runningThread.set(thread);
-            }
+        if (thread == null) {
+            LOG.warn("Unable to retrieve the thread of the current job 
execution");
         } else {
-            LOG.warn("Unable to retrieve the right thread related to the 
current job execution");
+            LOG.info("Interrupting job from thread {} at {} ", thread.getId(), 
DataFormat.format(new Date()));
+
+            long maxRetry = confDAO.find("tasks.interruptMaxRetries", 
"1").getValues().get(0).getLongValue();
+            for (int i = 0; i < maxRetry && thread.isAlive(); i++) {
+                thread.interrupt();
+            }
+            // if the thread is still alive, it should be available in the 
next stop
+            if (thread.isAlive()) {
+                this.runningThread.set(thread);
+            }
         }
     }
 }

Reply via email to