Skip to content

Commit b179314

Browse files
committed
The ConfigurationPoller always created a non-daemon thread. This patch uses
the ConnectionFactory.isDaemon() method to determine how the thread should be created.
1 parent 9b5626c commit b179314

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/main/java/net/spy/memcached/ConfigurationPoller.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
import java.util.Date;
1919
import java.util.Iterator;
2020
import java.util.List;
21+
import java.util.concurrent.Executors;
2122
import java.util.concurrent.ScheduledThreadPoolExecutor;
23+
import java.util.concurrent.ThreadFactory;
2224
import java.util.concurrent.TimeUnit;
2325

2426
import net.spy.memcached.compat.SpyThread;
@@ -57,14 +59,23 @@ public class ConfigurationPoller extends SpyThread{
5759

5860
//The executor is used to keep the task and it's execution independent. The scheduled thread polls takes care of
5961
//the periodic polling.
60-
private ScheduledThreadPoolExecutor scheduledExecutor = new ScheduledThreadPoolExecutor(1);
62+
private ScheduledThreadPoolExecutor scheduledExecutor;
6163

6264
public ConfigurationPoller(final MemcachedClient client){
63-
this(client, DEFAULT_POLL_INTERVAL);
65+
this(client, DEFAULT_POLL_INTERVAL, false);
6466
}
6567

66-
public ConfigurationPoller(final MemcachedClient client, long pollingInterval){
68+
public ConfigurationPoller(final MemcachedClient client, long pollingInterval, final boolean useDaemonThreads){
6769
this.client = client;
70+
this.scheduledExecutor = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
71+
@Override
72+
public Thread newThread(Runnable runnable) {
73+
Thread thread = Executors.defaultThreadFactory().newThread(runnable);
74+
thread.setDaemon(useDaemonThreads);
75+
return thread;
76+
}
77+
});
78+
setDaemon(useDaemonThreads);
6879

6980
//The explicit typed emptyList assignment avoids type warning.
7081
List<NodeEndPoint> emptyList = Collections.emptyList();

src/main/java/net/spy/memcached/MemcachedClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ private void initializeClientUsingConfigEndPoint(ConnectionFactory cf, InetSocke
346346
}
347347

348348
//Initialize and start the poller.
349-
configPoller = new ConfigurationPoller(this, cf.getDynamicModePollingInterval());
349+
configPoller = new ConfigurationPoller(this, cf.getDynamicModePollingInterval(), cf.isDaemon());
350350
configPoller.subscribeForClusterConfiguration(mconn);
351351
}
352352

0 commit comments

Comments
 (0)