diff --git a/exporters/metrics/util/src/main/java/io/opencensus/exporter/metrics/util/DaemonThreadFactory.java b/exporters/metrics/util/src/main/java/io/opencensus/exporter/metrics/util/DaemonThreadFactory.java deleted file mode 100644 index 39a1b0c623..0000000000 --- a/exporters/metrics/util/src/main/java/io/opencensus/exporter/metrics/util/DaemonThreadFactory.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2019, OpenCensus Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.opencensus.exporter.metrics.util; - -import com.google.common.util.concurrent.MoreExecutors; -import java.util.concurrent.ThreadFactory; - -/** - * A lightweight {@link ThreadFactory} to spawn threads in a GAE-Java7-compatible way. - * - * @since 0.19 - */ -// TODO(Hailong): Remove this once we use a callback to implement the exporter. -final class DaemonThreadFactory implements ThreadFactory { - // AppEngine runtimes have constraints on threading and socket handling - // that need to be accommodated. - private static final boolean IS_RESTRICTED_APPENGINE = - System.getProperty("com.google.appengine.runtime.environment") != null - && "1.7".equals(System.getProperty("java.specification.version")); - private static final ThreadFactory threadFactory = MoreExecutors.platformThreadFactory(); - - @Override - public Thread newThread(Runnable r) { - Thread thread = threadFactory.newThread(r); - if (!IS_RESTRICTED_APPENGINE) { - thread.setName("ExportWorkerThread"); - thread.setDaemon(true); - } - return thread; - } -} diff --git a/exporters/metrics/util/src/main/java/io/opencensus/exporter/metrics/util/IntervalMetricReader.java b/exporters/metrics/util/src/main/java/io/opencensus/exporter/metrics/util/IntervalMetricReader.java index 683f628b55..f795b9c126 100644 --- a/exporters/metrics/util/src/main/java/io/opencensus/exporter/metrics/util/IntervalMetricReader.java +++ b/exporters/metrics/util/src/main/java/io/opencensus/exporter/metrics/util/IntervalMetricReader.java @@ -39,7 +39,13 @@ public final class IntervalMetricReader { private IntervalMetricReader(Worker worker) { this.worker = worker; - this.workerThread = new DaemonThreadFactory().newThread(worker); + this.workerThread = new Thread(worker); + try { + this.workerThread.setName("ExportWorkerThread"); + this.workerThread.setDaemon(true); + } catch (SecurityException e) { + // OK if we can't set the name or daemon in this environment. + } workerThread.start(); } diff --git a/impl_core/src/main/java/io/opencensus/implcore/internal/DaemonThreadFactory.java b/impl_core/src/main/java/io/opencensus/implcore/internal/DaemonThreadFactory.java index e4481df49e..ee3b4a27af 100644 --- a/impl_core/src/main/java/io/opencensus/implcore/internal/DaemonThreadFactory.java +++ b/impl_core/src/main/java/io/opencensus/implcore/internal/DaemonThreadFactory.java @@ -16,14 +16,12 @@ package io.opencensus.implcore.internal; -import com.google.common.util.concurrent.MoreExecutors; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicInteger; /** A {@link ThreadFactory} implementation that starts all {@link Thread} as daemons. */ public final class DaemonThreadFactory implements ThreadFactory { private static final String DELIMITER = "-"; - private static final ThreadFactory threadFactory = MoreExecutors.platformThreadFactory(); private final AtomicInteger threadIdGen = new AtomicInteger(); private final String threadPrefix; @@ -38,8 +36,7 @@ public DaemonThreadFactory(String threadPrefix) { @Override public Thread newThread(Runnable r) { - Thread thread = threadFactory.newThread(r); - // AppEngine runtimes have constraints on thread renaming. + Thread thread = new Thread(r); try { thread.setName(threadPrefix + threadIdGen.getAndIncrement()); thread.setDaemon(true);