You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2014/02/17 08:24:12 UTC

svn commit: r1568885 - in /tomee/tomee/trunk/server: openejb-multicast/src/main/java/org/apache/openejb/server/discovery/ openejb-server/src/main/java/org/apache/openejb/server/

Author: rmannibucau
Date: Mon Feb 17 07:24:12 2014
New Revision: 1568885

URL: http://svn.apache.org/r1568885
Log:
we already had this issue but seems it was not fixed, using daemonthreadfactory everywhere in multicast + little refactory of our custom pool in servicepool

Modified:
    tomee/tomee/trunk/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/MulticastPulseAgent.java
    tomee/tomee/trunk/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/MultipointServer.java
    tomee/tomee/trunk/server/openejb-server/src/main/java/org/apache/openejb/server/ServicePool.java

Modified: tomee/tomee/trunk/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/MulticastPulseAgent.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/MulticastPulseAgent.java?rev=1568885&r1=1568884&r2=1568885&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/MulticastPulseAgent.java (original)
+++ tomee/tomee/trunk/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/MulticastPulseAgent.java Mon Feb 17 07:24:12 2014
@@ -6,6 +6,7 @@ import org.apache.openejb.server.Discove
 import org.apache.openejb.server.SelfManaging;
 import org.apache.openejb.server.ServerService;
 import org.apache.openejb.server.ServiceException;
+import org.apache.openejb.util.DaemonThreadFactory;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 import org.apache.openejb.util.OptionsLog;
@@ -122,7 +123,7 @@ public class MulticastPulseAgent impleme
                 length = 1;
             }
 
-            executor = Executors.newFixedThreadPool(length * 3);
+            executor = Executors.newFixedThreadPool(length * 3, new DaemonThreadFactory("multicast-pulse-agent-"));
         }
 
         return executor;

Modified: tomee/tomee/trunk/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/MultipointServer.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/MultipointServer.java?rev=1568885&r1=1568884&r2=1568885&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/MultipointServer.java (original)
+++ tomee/tomee/trunk/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/MultipointServer.java Mon Feb 17 07:24:12 2014
@@ -19,6 +19,7 @@ package org.apache.openejb.server.discov
 import org.apache.openejb.monitoring.Event;
 import org.apache.openejb.monitoring.Managed;
 import org.apache.openejb.server.ServerRuntimeException;
+import org.apache.openejb.util.DaemonThreadFactory;
 import org.apache.openejb.util.Duration;
 import org.apache.openejb.util.Join;
 import org.apache.openejb.util.LogCategory;
@@ -1213,7 +1214,7 @@ public class MultipointServer {
         return colors[(int) index];
     }
 
-    private final Executor dnsResolutionQueue = Executors.newFixedThreadPool(2);
+    private final Executor dnsResolutionQueue = Executors.newFixedThreadPool(2, new DaemonThreadFactory("multipoint-server-"));
 
     private class Host {
 

Modified: tomee/tomee/trunk/server/openejb-server/src/main/java/org/apache/openejb/server/ServicePool.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-server/src/main/java/org/apache/openejb/server/ServicePool.java?rev=1568885&r1=1568884&r2=1568885&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-server/src/main/java/org/apache/openejb/server/ServicePool.java (original)
+++ tomee/tomee/trunk/server/openejb-server/src/main/java/org/apache/openejb/server/ServicePool.java Mon Feb 17 07:24:12 2014
@@ -92,71 +92,69 @@ public class ServicePool extends ServerS
          is true then a final attempt is made to run the runnable in the current thread (the service thread).
          */
 
-        threadPool = new ThreadPoolExecutor(threadCore, threads, keepAliveTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(queue));
-        threadPool.setThreadFactory(new ThreadFactory() {
-
-            private final AtomicInteger i = new AtomicInteger(0);
-
-            @Override
-            public Thread newThread(final Runnable r) {
-                final Thread t = new Thread(r, "OpenEJB." + ServicePool.this.getName() + "." + i.incrementAndGet());
-                t.setDaemon(true);
-                t.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
-                    @Override
-                    public void uncaughtException(final Thread t, final Throwable e) {
-                        log.error("ServicePool '" + ServicePool.this.getName() + "': Uncaught error in: " + t.getName(), e);
-                    }
-                });
-
-                return t;
-            }
-
-        });
-
         final int c = threadCore;
         final int t = threads;
         final int q = queue;
 
-        threadPool.setRejectedExecutionHandler(new RejectedExecutionHandler() {
-            @Override
-            public void rejectedExecution(final Runnable r, final ThreadPoolExecutor tpe) {
+        threadPool = new ThreadPoolExecutor(threadCore, threads, keepAliveTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(queue),
+                new ThreadFactory() {
+                    private final AtomicInteger i = new AtomicInteger(0);
 
-                if (null == r || null == tpe || tpe.isShutdown() || tpe.isTerminated() || tpe.isTerminating()) {
-                    return;
-                }
+                    @Override
+                    public Thread newThread(final Runnable r) {
+                        final Thread t = new Thread(r, "OpenEJB." + ServicePool.this.getName() + "." + i.incrementAndGet());
+                        t.setDaemon(true);
+                        t.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
+                            @Override
+                            public void uncaughtException(final Thread t, final Throwable e) {
+                                log.error("ServicePool '" + ServicePool.this.getName() + "': Uncaught error in: " + t.getName(), e);
+                            }
+                        });
 
-                if (log.isWarningEnabled()) {
-                    log.warning(String.format("ServicePool '" + ServicePool.this.getName() + "' with (%1$s) threads is at capicity (%2$s) for queue (%3$s) on process: %4$s"
-                                              + "\nConsider increasing the 'threadCore','threads' and 'queue' size properties.", c, t, q, r));
-                }
+                        return t;
+                    }
 
-                boolean offer = false;
-                try {
-                    offer = tpe.getQueue().offer(r, 10, TimeUnit.SECONDS);
-                } catch (InterruptedException e) {
-                    //Ignore
-                }
+                },
+                new RejectedExecutionHandler() {
+                    @Override
+                    public void rejectedExecution(final Runnable r, final ThreadPoolExecutor tpe) {
 
-                if (!offer) {
+                        if (null == r || null == tpe || tpe.isShutdown() || tpe.isTerminated() || tpe.isTerminating()) {
+                            return;
+                        }
 
-                    if (block) {
+                        if (log.isWarningEnabled()) {
+                            log.warning(String.format("ServicePool '" + ServicePool.this.getName() + "' with (%1$s) threads is at capicity (%2$s) for queue (%3$s) on process: %4$s"
+                                                      + "\nConsider increasing the 'threadCore','threads' and 'queue' size properties.", c, t, q, r));
+                        }
+
+                        boolean offer = false;
                         try {
-                            //Last ditch effort to run the process in the current thread
-                            r.run();
+                            offer = tpe.getQueue().offer(r, 10, TimeUnit.SECONDS);
+                        } catch (InterruptedException e) {
+                            //Ignore
+                        }
 
-                            log.warning("ServicePool '" + ServicePool.this.getName() + "' forced execution on the current server thread: " + r
-                                        + "\nIt is highly recommended that the service 'threadCore','threads' and 'queue' size properties are increased!");
+                        if (!offer) {
 
-                        } catch (Throwable e) {
-                            log.error("ServicePool '" + ServicePool.this.getName() + "' failed to run a process in the current server thread: " + r);
+                            if (block) {
+                                try {
+                                    //Last ditch effort to run the process in the current thread
+                                    r.run();
+
+                                    log.warning("ServicePool '" + ServicePool.this.getName() + "' forced execution on the current server thread: " + r
+                                                + "\nIt is highly recommended that the service 'threadCore','threads' and 'queue' size properties are increased!");
+
+                                } catch (Throwable e) {
+                                    log.error("ServicePool '" + ServicePool.this.getName() + "' failed to run a process in the current server thread: " + r);
+                                }
+                            } else {
+                                log.error("ServicePool '" + ServicePool.this.getName() + "' rejected asynchronous process: " + r
+                                          + "\nIt is strongly advised that the 'threadCore', 'threads', 'queue' size and 'block' properties are modified to prevent data loss!");
+                            }
                         }
-                    } else {
-                        log.error("ServicePool '" + ServicePool.this.getName() + "' rejected asynchronous process: " + r
-                                  + "\nIt is strongly advised that the 'threadCore', 'threads', 'queue' size and 'block' properties are modified to prevent data loss!");
                     }
-                }
-            }
-        });
+                });
 
         SystemInstance.get().setComponent(ServicePool.class, this);