Skip to content

Commit dc89cd1

Browse files
committed
Name agent writer threadpools and set to daemon
This allows a clean shutdown, instead of keeping the vm running.
1 parent a52e8ad commit dc89cd1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

dd-trace/src/main/java/com/datadoghq/trace/writer/DDAgentWriter.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import com.datadoghq.trace.DDBaseSpan;
44
import com.datadoghq.trace.Service;
55
import com.google.auto.service.AutoService;
6+
import com.google.common.util.concurrent.ThreadFactoryBuilder;
67
import java.util.List;
78
import java.util.Map;
89
import java.util.concurrent.Callable;
910
import java.util.concurrent.ExecutorService;
1011
import java.util.concurrent.Executors;
1112
import java.util.concurrent.Future;
1213
import java.util.concurrent.ScheduledExecutorService;
14+
import java.util.concurrent.ThreadFactory;
1315
import java.util.concurrent.TimeUnit;
1416
import java.util.concurrent.TimeoutException;
1517
import lombok.extern.slf4j.Slf4j;
@@ -40,12 +42,16 @@ public class DDAgentWriter implements Writer {
4042
/** Flush interval for the API in seconds */
4143
static final long FLUSH_TIME_SECONDS = 1;
4244

45+
private final ThreadFactory agentWriterThreadFactory =
46+
new ThreadFactoryBuilder().setNameFormat("dd-agent-writer-%d").setDaemon(true).build();
47+
4348
/** Scheduled thread pool, acting like a cron */
44-
private final ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(1);
45-
// FIXME: Properly name these threads to better identify them as ours.
49+
private final ScheduledExecutorService scheduledExecutor =
50+
Executors.newScheduledThreadPool(1, agentWriterThreadFactory);
4651

4752
/** Effective thread pool, where real logic is done */
48-
private final ExecutorService executor = Executors.newSingleThreadExecutor();
53+
private final ExecutorService executor =
54+
Executors.newSingleThreadExecutor(agentWriterThreadFactory);
4955

5056
/** The DD agent api */
5157
private final DDApi api;

0 commit comments

Comments
 (0)