Skip to content
This repository was archived by the owner on Dec 23, 2023. It is now read-only.

Commit b30318d

Browse files
rghetiasongy23
authored andcommitted
use regular thread for to expose errors in appengine (#1955)
* use regular thread for IntervalMetricReader to expose error logs in appengine. * add try-catch for SecurityException.
1 parent bb3770a commit b30318d

File tree

3 files changed

+8
-50
lines changed

3 files changed

+8
-50
lines changed

exporters/metrics/util/src/main/java/io/opencensus/exporter/metrics/util/DaemonThreadFactory.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

exporters/metrics/util/src/main/java/io/opencensus/exporter/metrics/util/IntervalMetricReader.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ public final class IntervalMetricReader {
3939

4040
private IntervalMetricReader(Worker worker) {
4141
this.worker = worker;
42-
this.workerThread = new DaemonThreadFactory().newThread(worker);
42+
this.workerThread = new Thread(worker);
43+
try {
44+
this.workerThread.setName("ExportWorkerThread");
45+
this.workerThread.setDaemon(true);
46+
} catch (SecurityException e) {
47+
// OK if we can't set the name or daemon in this environment.
48+
}
4349
workerThread.start();
4450
}
4551

impl_core/src/main/java/io/opencensus/implcore/internal/DaemonThreadFactory.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616

1717
package io.opencensus.implcore.internal;
1818

19-
import com.google.common.util.concurrent.MoreExecutors;
2019
import java.util.concurrent.ThreadFactory;
2120
import java.util.concurrent.atomic.AtomicInteger;
2221

2322
/** A {@link ThreadFactory} implementation that starts all {@link Thread} as daemons. */
2423
public final class DaemonThreadFactory implements ThreadFactory {
2524
private static final String DELIMITER = "-";
26-
private static final ThreadFactory threadFactory = MoreExecutors.platformThreadFactory();
2725
private final AtomicInteger threadIdGen = new AtomicInteger();
2826
private final String threadPrefix;
2927

@@ -38,8 +36,7 @@ public DaemonThreadFactory(String threadPrefix) {
3836

3937
@Override
4038
public Thread newThread(Runnable r) {
41-
Thread thread = threadFactory.newThread(r);
42-
// AppEngine runtimes have constraints on thread renaming.
39+
Thread thread = new Thread(r);
4340
try {
4441
thread.setName(threadPrefix + threadIdGen.getAndIncrement());
4542
thread.setDaemon(true);

0 commit comments

Comments
 (0)