This repository has been archived by the owner on Dec 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 202
use regular thread for to expose errors in appengine #1955
Merged
songy23
merged 2 commits into
census-instrumentation:master
from
rghetia:change_appengine_thread
Jul 30, 2019
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
45 changes: 0 additions & 45 deletions
45
...s/metrics/util/src/main/java/io/opencensus/exporter/metrics/util/DaemonThreadFactory.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it safe to remove this try-catch clause? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.