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

use regular thread for to expose errors in appengine #1955

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public final class IntervalMetricReader {

private IntervalMetricReader(Worker worker) {
this.worker = worker;
this.workerThread = new DaemonThreadFactory().newThread(worker);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this change? It looks to me nothing changed for JDK 8+. The previous approach only restricts JDK 7.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous approach created thread using MoreExecutors.platformThreadFactory() for all JDK. We just need regular thread for logging to work.

this.workerThread = new Thread(worker);
this.workerThread.setName("ExportWorkerThread");
this.workerThread.setDaemon(true);
workerThread.start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -38,14 +36,9 @@ public DaemonThreadFactory(String threadPrefix) {

@Override
public Thread newThread(Runnable r) {
Thread thread = threadFactory.newThread(r);
// AppEngine runtimes have constraints on thread renaming.
try {
thread.setName(threadPrefix + threadIdGen.getAndIncrement());
thread.setDaemon(true);
} catch (SecurityException e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to remove this try-catch clause?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constraints on thread renaming is from AppEngine threads. Since we are not using them it should be okay. But let me put it back as it doesn't hurt to have try-catch clause.

// OK if we can't set the name or daemon in this environment.
}
Thread thread = new Thread(r);
thread.setName(threadPrefix + threadIdGen.getAndIncrement());
thread.setDaemon(true);
return thread;
}
}