tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kfuj...@apache.org
Subject svn commit: r1345026 - /tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java
Date Fri, 01 Jun 2012 09:38:32 GMT
Author: kfujino
Date: Fri Jun  1 09:38:31 2012
New Revision: 1345026

URL: http://svn.apache.org/viewvc?rev=1345026&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=53342
To avoid BindException, make startStopThreads into a demon thread.

Modified:
    tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java

Modified: tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java?rev=1345026&r1=1345025&r2=1345026&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java Fri Jun  1 09:38:31 2012
@@ -31,8 +31,10 @@ import java.util.concurrent.BlockingQueu
 import java.util.concurrent.Callable;
 import java.util.concurrent.Future;
 import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -1042,7 +1044,8 @@ public abstract class ContainerBase exte
         startStopExecutor = new ThreadPoolExecutor(
                 getStartStopThreadsInternal(),
                 getStartStopThreadsInternal(), 10, TimeUnit.SECONDS,
-                startStopQueue);
+                startStopQueue,
+                new StartStopThreadFactory(getName() + "-startStop-"));
         startStopExecutor.allowCoreThreadTimeOut(true);
         super.initInternal();
     }
@@ -1596,4 +1599,23 @@ public abstract class ContainerBase exte
             return null;
         }
     }
+
+    private static class StartStopThreadFactory implements ThreadFactory {
+        private ThreadGroup group;
+        private AtomicInteger threadNumber = new AtomicInteger(1);
+        private String namePrefix;
+        
+        public StartStopThreadFactory(String namePrefix) {
+            SecurityManager s = System.getSecurityManager();
+            group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
+            this.namePrefix = namePrefix;
+        }
+        
+        @Override
+        public Thread newThread(Runnable r) {
+            Thread thread = new Thread(group, r, namePrefix + threadNumber.getAndIncrement());
+            thread.setDaemon(true);
+            return thread;
+        }
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message