aboutsummaryrefslogtreecommitdiffstats
path: root/impl
diff options
context:
space:
mode:
authorKun Zhang <zhangkun83@users.noreply.github.com>2017-10-17 07:40:07 -0700
committerBogdan Drutu <bdrutu@google.com>2017-10-17 07:40:07 -0700
commit8be62fbe4c26b02d33b72b67ef5d1bf687676dc8 (patch)
treecf2165759e5aa3857514bec452716363e5fe8b94 /impl
parent6195c953cd4ae25d3515b1a8db0a4686457a493c (diff)
downloadplatform_external_opencensus-java-8be62fbe4c26b02d33b72b67ef5d1bf687676dc8.tar.gz
platform_external_opencensus-java-8be62fbe4c26b02d33b72b67ef5d1bf687676dc8.tar.bz2
platform_external_opencensus-java-8be62fbe4c26b02d33b72b67ef5d1bf687676dc8.zip
Make disruptor thread daemon. (#706)
* Make disruptor thread daemon. Resolves https://github.com/grpc/grpc-java/issues/3578 * Make final final
Diffstat (limited to 'impl')
-rw-r--r--impl/src/main/java/io/opencensus/impl/internal/DisruptorEventQueue.java14
1 files changed, 13 insertions, 1 deletions
diff --git a/impl/src/main/java/io/opencensus/impl/internal/DisruptorEventQueue.java b/impl/src/main/java/io/opencensus/impl/internal/DisruptorEventQueue.java
index 32bd3fdc..f825d526 100644
--- a/impl/src/main/java/io/opencensus/impl/internal/DisruptorEventQueue.java
+++ b/impl/src/main/java/io/opencensus/impl/internal/DisruptorEventQueue.java
@@ -24,6 +24,8 @@ import com.lmax.disruptor.dsl.Disruptor;
import com.lmax.disruptor.dsl.ProducerType;
import io.opencensus.implcore.internal.EventQueue;
import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.concurrent.ThreadSafe;
/**
@@ -118,6 +120,16 @@ public final class DisruptorEventQueue implements EventQueue {
}
}
+ private static final AtomicInteger threadIdGen = new AtomicInteger();
+ private static final ThreadFactory threadFactory = new ThreadFactory() {
+ @Override
+ public Thread newThread(Runnable r) {
+ Thread thread = new Thread(r, "CensusDisruptor-" + threadIdGen.getAndIncrement());
+ thread.setDaemon(true);
+ return thread;
+ }
+ };
+
// The single instance of the class.
private static final DisruptorEventQueue eventQueue = new DisruptorEventQueue();
// The event queue is built on this {@link Disruptor}.
@@ -141,7 +153,7 @@ public final class DisruptorEventQueue implements EventQueue {
new Disruptor<InstrumentationEvent>(
new InstrumentationEventFactory(),
bufferSize,
- Executors.newSingleThreadExecutor(),
+ Executors.newSingleThreadExecutor(threadFactory),
ProducerType.MULTI,
new SleepingWaitStrategy());
disruptor.handleEventsWith(new InstrumentationEventHandler());