|
31 | 31 | import java.util.concurrent.Executors;
|
32 | 32 | import java.util.concurrent.ScheduledExecutorService;
|
33 | 33 | import java.util.concurrent.ScheduledFuture;
|
| 34 | +import java.util.concurrent.ThreadFactory; |
34 | 35 | import java.util.concurrent.TimeUnit;
|
35 | 36 | import java.util.concurrent.atomic.AtomicBoolean;
|
| 37 | +import java.util.concurrent.atomic.AtomicInteger; |
36 | 38 |
|
37 | 39 | /**
|
38 | 40 | * Class responsible for sniffing nodes from some source (default is elasticsearch itself) and setting them to a provided instance of
|
|
45 | 47 | public class Sniffer implements Closeable {
|
46 | 48 |
|
47 | 49 | private static final Log logger = LogFactory.getLog(Sniffer.class);
|
| 50 | + private static final String SNIFFER_THREAD_NAME = "es_rest_client_sniffer"; |
48 | 51 |
|
49 | 52 | private final Task task;
|
50 | 53 |
|
@@ -79,7 +82,8 @@ private Task(HostsSniffer hostsSniffer, RestClient restClient, long sniffInterva
|
79 | 82 | this.restClient = restClient;
|
80 | 83 | this.sniffIntervalMillis = sniffIntervalMillis;
|
81 | 84 | this.sniffAfterFailureDelayMillis = sniffAfterFailureDelayMillis;
|
82 |
| - this.scheduledExecutorService = Executors.newScheduledThreadPool(1); |
| 85 | + SnifferThreadFactory threadFactory = new SnifferThreadFactory(SNIFFER_THREAD_NAME); |
| 86 | + this.scheduledExecutorService = Executors.newScheduledThreadPool(1, threadFactory); |
83 | 87 | scheduleNextRun(0);
|
84 | 88 | }
|
85 | 89 |
|
@@ -151,4 +155,24 @@ synchronized void shutdown() {
|
151 | 155 | public static SnifferBuilder builder(RestClient restClient) {
|
152 | 156 | return new SnifferBuilder(restClient);
|
153 | 157 | }
|
| 158 | + |
| 159 | + private static class SnifferThreadFactory implements ThreadFactory { |
| 160 | + |
| 161 | + private final AtomicInteger threadNumber = new AtomicInteger(1); |
| 162 | + private final String namePrefix; |
| 163 | + private final ThreadFactory originalThreadFactory; |
| 164 | + |
| 165 | + private SnifferThreadFactory(String namePrefix) { |
| 166 | + this.namePrefix = namePrefix; |
| 167 | + this.originalThreadFactory = Executors.defaultThreadFactory(); |
| 168 | + } |
| 169 | + |
| 170 | + @Override |
| 171 | + public Thread newThread(Runnable r) { |
| 172 | + Thread t = this.originalThreadFactory.newThread(r); |
| 173 | + t.setName(namePrefix + "[T#" + threadNumber.getAndIncrement() + "]"); |
| 174 | + t.setDaemon(true); |
| 175 | + return t; |
| 176 | + } |
| 177 | + } |
154 | 178 | }
|
0 commit comments