Name agent writer threadpools and set to daemon

This allows a clean shutdown, instead of keeping the vm running.
This commit is contained in:
Tyler Benson 2017-12-05 16:06:38 -08:00
parent a52e8adece
commit dc89cd174e
1 changed files with 9 additions and 3 deletions

View File

@ -3,6 +3,7 @@ package com.datadoghq.trace.writer;
import com.datadoghq.trace.DDBaseSpan;
import com.datadoghq.trace.Service;
import com.google.auto.service.AutoService;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
@ -10,6 +11,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import lombok.extern.slf4j.Slf4j;
@ -40,12 +42,16 @@ public class DDAgentWriter implements Writer {
/** Flush interval for the API in seconds */
static final long FLUSH_TIME_SECONDS = 1;
private final ThreadFactory agentWriterThreadFactory =
new ThreadFactoryBuilder().setNameFormat("dd-agent-writer-%d").setDaemon(true).build();
/** Scheduled thread pool, acting like a cron */
private final ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(1);
// FIXME: Properly name these threads to better identify them as ours.
private final ScheduledExecutorService scheduledExecutor =
Executors.newScheduledThreadPool(1, agentWriterThreadFactory);
/** Effective thread pool, where real logic is done */
private final ExecutorService executor = Executors.newSingleThreadExecutor();
private final ExecutorService executor =
Executors.newSingleThreadExecutor(agentWriterThreadFactory);
/** The DD agent api */
private final DDApi api;