|
18 | 18 | import java.util.Date;
|
19 | 19 | import java.util.Iterator;
|
20 | 20 | import java.util.List;
|
| 21 | +import java.util.concurrent.Executors; |
21 | 22 | import java.util.concurrent.ScheduledThreadPoolExecutor;
|
| 23 | +import java.util.concurrent.ThreadFactory; |
22 | 24 | import java.util.concurrent.TimeUnit;
|
23 | 25 |
|
24 | 26 | import net.spy.memcached.compat.SpyThread;
|
@@ -57,14 +59,23 @@ public class ConfigurationPoller extends SpyThread{
|
57 | 59 |
|
58 | 60 | //The executor is used to keep the task and it's execution independent. The scheduled thread polls takes care of
|
59 | 61 | //the periodic polling.
|
60 |
| - private ScheduledThreadPoolExecutor scheduledExecutor = new ScheduledThreadPoolExecutor(1); |
| 62 | + private ScheduledThreadPoolExecutor scheduledExecutor; |
61 | 63 |
|
62 | 64 | public ConfigurationPoller(final MemcachedClient client){
|
63 |
| - this(client, DEFAULT_POLL_INTERVAL); |
| 65 | + this(client, DEFAULT_POLL_INTERVAL, false); |
64 | 66 | }
|
65 | 67 |
|
66 |
| - public ConfigurationPoller(final MemcachedClient client, long pollingInterval){ |
| 68 | + public ConfigurationPoller(final MemcachedClient client, long pollingInterval, final boolean useDaemonThreads){ |
67 | 69 | 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); |
68 | 79 |
|
69 | 80 | //The explicit typed emptyList assignment avoids type warning.
|
70 | 81 | List<NodeEndPoint> emptyList = Collections.emptyList();
|
|
0 commit comments