You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ra...@apache.org on 2008/03/18 07:45:27 UTC
svn commit: r638238 -
/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/discovery/simple/SimpleDiscoveryAgent.java
Author: rajdavies
Date: Mon Mar 17 23:45:25 2008
New Revision: 638238
URL: http://svn.apache.org/viewvc?rev=638238&view=rev
Log:
Use ThreadPool for stopping services
Modified:
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/discovery/simple/SimpleDiscoveryAgent.java
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/discovery/simple/SimpleDiscoveryAgent.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/discovery/simple/SimpleDiscoveryAgent.java?rev=638238&r1=638237&r2=638238&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/discovery/simple/SimpleDiscoveryAgent.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/discovery/simple/SimpleDiscoveryAgent.java Mon Mar 17 23:45:25 2008
@@ -18,6 +18,10 @@
import java.io.IOException;
import java.net.URI;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.activemq.command.DiscoveryEvent;
@@ -35,7 +39,7 @@
public class SimpleDiscoveryAgent implements DiscoveryAgent {
private final static Log LOG = LogFactory.getLog(SimpleDiscoveryAgent.class);
-
+ private static final ThreadPoolExecutor ASYNC_TASKS;
private long initialReconnectDelay = 1000;
private long maxReconnectDelay = 1000 * 30;
private long backOffMultiplier = 2;
@@ -106,7 +110,7 @@
if (event.failed.compareAndSet(false, true)) {
listener.onServiceRemove(event);
- Thread thread = new Thread() {
+ ASYNC_TASKS.execute(new Runnable() {
public void run() {
// We detect a failed connection attempt because the service
@@ -160,9 +164,7 @@
listener.onServiceAdd(event);
}
- };
- thread.setDaemon(true);
- thread.start();
+ });
}
}
@@ -213,5 +215,16 @@
public void setUseExponentialBackOff(boolean useExponentialBackOff) {
this.useExponentialBackOff = useExponentialBackOff;
}
+
+ static {
+ ASYNC_TASKS = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 30, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new ThreadFactory() {
+ public Thread newThread(Runnable runnable) {
+ Thread thread = new Thread(runnable, "Simple Discovery Agent: "+runnable);
+ thread.setDaemon(true);
+ return thread;
+ }
+ });
+ }
+
}