roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ko...@apache.org
Subject svn commit: r1714407 - in /roller/trunk/app/src/main/java/org/apache/roller: util/RollerConstants.java weblogger/business/HitCountQueue.java weblogger/business/runnable/TaskScheduler.java weblogger/business/runnable/ThreadManagerImpl.java
Date Sun, 15 Nov 2015 06:27:16 GMT
Author: kohei
Date: Sun Nov 15 06:27:15 2015
New Revision: 1714407

URL: http://svn.apache.org/viewvc?rev=1714407&view=rev
Log:
Fix shutdown procedure of ThreadManagerImpl and TaskScheduler (it won't stop if interrupt()
has been invoked during the thread is running)

Modified:
    roller/trunk/app/src/main/java/org/apache/roller/util/RollerConstants.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/HitCountQueue.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/runnable/TaskScheduler.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/runnable/ThreadManagerImpl.java

Modified: roller/trunk/app/src/main/java/org/apache/roller/util/RollerConstants.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/util/RollerConstants.java?rev=1714407&r1=1714406&r2=1714407&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/util/RollerConstants.java (original)
+++ roller/trunk/app/src/main/java/org/apache/roller/util/RollerConstants.java Sun Nov 15
06:27:15 2015
@@ -36,6 +36,9 @@ public final class RollerConstants {
 
     public static final int TEXTWIDTH_255 = 255;
 
+    public static final int GRACEFUL_SHUTDOWN_WAIT_IN_SECONDS = 20;
+    public static final int GRACEFUL_SHUTDOWN_WAIT_IN_MILLISECONDS = GRACEFUL_SHUTDOWN_WAIT_IN_SECONDS
* SEC_IN_MS;
+
     private RollerConstants() {
         // never instantiable
         throw new AssertionError();

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/HitCountQueue.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/HitCountQueue.java?rev=1714407&r1=1714406&r2=1714407&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/HitCountQueue.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/HitCountQueue.java
Sun Nov 15 06:27:15 2015
@@ -115,10 +115,9 @@ public final class HitCountQueue {
             log.info("stopping worker "+this.worker.getName());
             worker.interrupt();
             try {
-                // wait 10 seconds for graceful shutdown
-                worker.join(10 * 1000);
+                worker.join(RollerConstants.GRACEFUL_SHUTDOWN_WAIT_IN_MILLISECONDS);
             } catch (InterruptedException e) {
-                log.debug("interrupted", e);
+                log.debug(e.getMessage(), e);
             }
         }
         

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/runnable/TaskScheduler.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/runnable/TaskScheduler.java?rev=1714407&r1=1714406&r2=1714407&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/runnable/TaskScheduler.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/runnable/TaskScheduler.java
Sun Nov 15 06:27:15 2015
@@ -23,6 +23,8 @@ import java.util.Date;
 import java.util.List;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.util.DateUtil;
@@ -30,6 +32,8 @@ import org.apache.roller.util.RollerCons
 import org.apache.roller.weblogger.business.WebloggerFactory;
 import org.apache.roller.weblogger.pojos.TaskLock;
 
+import static org.apache.roller.util.RollerConstants.GRACEFUL_SHUTDOWN_WAIT_IN_SECONDS;
+
 
 /**
  * Manages scheduling of periodic tasks.
@@ -65,7 +69,7 @@ public class TaskScheduler implements Ru
         boolean firstRun = true;
         
         // run forever, or until we get interrupted
-        while(true) {
+        while (!Thread.currentThread().isInterrupted()) {
             try {
                 // get current time
                 Date now = new Date();
@@ -111,13 +115,19 @@ public class TaskScheduler implements Ru
                 }
                 
             } catch (InterruptedException ex) {
-                // thread interrupted
                 log.debug("Thread interrupted, scheduler is stopping");
-                pool.shutdownNow();
                 break;
             }
         }
-        
+
+        // thread interrupted
+        pool.shutdownNow();
+        try {
+            pool.awaitTermination(GRACEFUL_SHUTDOWN_WAIT_IN_SECONDS, TimeUnit.SECONDS);
+            log.debug("TaskScheduler executor was terminated successfully");
+        } catch (InterruptedException e) {
+            log.debug(e.getMessage(), e);
+        }
     }
     
     

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/runnable/ThreadManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/runnable/ThreadManagerImpl.java?rev=1714407&r1=1714406&r2=1714407&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/runnable/ThreadManagerImpl.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/runnable/ThreadManagerImpl.java
Sun Nov 15 06:27:15 2015
@@ -24,6 +24,8 @@ import java.util.List;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -33,6 +35,8 @@ import org.apache.roller.weblogger.busin
 import org.apache.roller.weblogger.config.WebloggerConfig;
 import org.apache.roller.weblogger.pojos.TaskLock;
 
+import static org.apache.roller.util.RollerConstants.GRACEFUL_SHUTDOWN_WAIT_IN_MILLISECONDS;
+import static org.apache.roller.util.RollerConstants.GRACEFUL_SHUTDOWN_WAIT_IN_SECONDS;
 
 /**
  * Manage Roller's thread use.
@@ -142,11 +146,22 @@ public abstract class ThreadManagerImpl
         
         // trigger an immediate shutdown of any backgrounded tasks
         serviceScheduler.shutdownNow();
-        
+        try {
+            serviceScheduler.awaitTermination(GRACEFUL_SHUTDOWN_WAIT_IN_SECONDS, TimeUnit.SECONDS);
+        } catch (InterruptedException e) {
+            LOG.debug(e.getMessage(), e);
+        }
+
         // only stop if we are already running
         if(schedulerThread != null) {
             LOG.debug("Stopping scheduler");
             schedulerThread.interrupt();
+            try {
+                schedulerThread.join(GRACEFUL_SHUTDOWN_WAIT_IN_MILLISECONDS);
+                LOG.debug("Scheduler was stopped successfully");
+            } catch (InterruptedException e) {
+                LOG.debug(e.getMessage(), e);
+            }
         }
     }
     



Mime
View raw message