diff options
| author | Kun Zhang <zhangkun83@users.noreply.github.com> | 2017-10-17 07:40:07 -0700 |
|---|---|---|
| committer | Bogdan Drutu <bdrutu@google.com> | 2017-10-17 07:40:07 -0700 |
| commit | 8be62fbe4c26b02d33b72b67ef5d1bf687676dc8 (patch) | |
| tree | cf2165759e5aa3857514bec452716363e5fe8b94 /impl | |
| parent | 6195c953cd4ae25d3515b1a8db0a4686457a493c (diff) | |
| download | platform_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.java | 14 |
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()); |
