You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tv...@apache.org on 2015/07/12 13:57:51 UTC
svn commit: r1690447 - in
/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs:
engine/control/CompositeCacheManager.java
utils/threadpool/ThreadPoolManager.java
Author: tv
Date: Sun Jul 12 11:57:51 2015
New Revision: 1690447
URL: http://svn.apache.org/r1690447
Log:
Add orderly shutdown for thread pools
Modified:
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheManager.java
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/threadpool/ThreadPoolManager.java
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheManager.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheManager.java?rev=1690447&r1=1690446&r2=1690447&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheManager.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheManager.java Sun Jul 12 11:57:51 2015
@@ -19,6 +19,23 @@ package org.apache.commons.jcs.engine.co
* under the License.
*/
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.management.ManagementFactory;
+import java.security.AccessControlException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
import org.apache.commons.jcs.access.exception.CacheException;
import org.apache.commons.jcs.admin.JCSAdminBean;
import org.apache.commons.jcs.auxiliary.AuxiliaryCache;
@@ -44,23 +61,6 @@ import org.apache.commons.jcs.utils.thre
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.management.ManagementFactory;
-import java.security.AccessControlException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-
/**
* Manages a composite cache. This provides access to caches and is the primary way to shutdown the
* caching system as a whole.
@@ -657,6 +657,9 @@ public class CompositeCacheManager
// shutdown all scheduled jobs
this.scheduledExecutor.shutdownNow();
+ // shutdown all thread pools
+ ThreadPoolManager.dispose();
+
// notify any observers
synchronized ( shutdownObservers )
{
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/threadpool/ThreadPoolManager.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/threadpool/ThreadPoolManager.java?rev=1690447&r1=1690446&r2=1690447&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/threadpool/ThreadPoolManager.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/threadpool/ThreadPoolManager.java Sun Jul 12 11:57:51 2015
@@ -19,11 +19,6 @@ package org.apache.commons.jcs.utils.thr
* under the License.
*/
-import org.apache.commons.jcs.utils.props.PropertyLoader;
-import org.apache.commons.jcs.utils.threadpool.PoolConfiguration.WhenBlockedPolicy;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Properties;
@@ -32,6 +27,11 @@ import java.util.concurrent.LinkedBlocki
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
+import org.apache.commons.jcs.utils.props.PropertyLoader;
+import org.apache.commons.jcs.utils.threadpool.PoolConfiguration.WhenBlockedPolicy;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
/**
* This manages threadpools for an application using Doug Lea's Util Concurrent package.
* http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html
@@ -99,17 +99,14 @@ public class ThreadPoolManager
/** The default config, created using property defaults if present, else those above. */
private static PoolConfiguration defaultConfig;
- /** This is the default value. */
- public static final String DEFAULT_PROPS_FILE_NAME = "cache.ccf";
-
/** Setting this after initialization will have no effect. */
private static String propsFileName = null;
/** the root property name */
- public static String PROP_NAME_ROOT = "thread_pool";
+ private static final String PROP_NAME_ROOT = "thread_pool";
/** default property file name */
- private static String DEFAULT_PROP_NAME_ROOT = "thread_pool.default";
+ private static final String DEFAULT_PROP_NAME_ROOT = "thread_pool.default";
/**
* You can specify the properties to be used to configure the thread pool. Setting this post
@@ -206,6 +203,29 @@ public class ThreadPoolManager
}
/**
+ * Dispose of the instance of the ThreadPoolManger and shut down all thread pools
+ */
+ public static synchronized void dispose()
+ {
+ if ( INSTANCE != null )
+ {
+ for ( String poolName : INSTANCE.getPoolNames())
+ {
+ try
+ {
+ INSTANCE.getPool(poolName).shutdownNow();
+ }
+ catch (Throwable t)
+ {
+ log.warn("Failed to close pool " + poolName, t);
+ }
+ }
+
+ INSTANCE = null;
+ }
+ }
+
+ /**
* Returns a pool by name. If a pool by this name does not exist in the configuration file or
* properties, one will be created using the default values.
* <p>