-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trace Stapler request processing #148
Conversation
3b3105f (plus a local |
private static List<ApplicationTracer> getTracers() { | ||
if (tracers == null) { | ||
synchronized (ApplicationTracer.class) { | ||
if (tracers == null) { |
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.
Double-checked locking. Delete the outer null check.
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.
Not what I had in mind, but at least no longer apparently vulnerable to data corruption.
} | ||
} | ||
|
||
private static volatile List<ApplicationTracer> tracers; |
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.
Pointless for this to be volatile
, since you have the synchronized
block.
tracers = t; | ||
} | ||
} | ||
return tracers; |
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.
This should really be inside the synchronized
block. I think it is harmless to have it outside, since there will be a synchronization barrier before, but definitely not the best style.
private static List<ApplicationTracer> getTracers() { | ||
synchronized (ApplicationTracer.class) { | ||
if (tracers == null) { | ||
List<ApplicationTracer> t = new ArrayList<>(); |
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.
You do not need a separate variable. You can initialize tracers
directly, since it is protected by a synchronization barrier.
FTR all you need is something like: private static List<X> xs;
static synchronized List<X> xs() {
if (xs == null) {
xs = new ArrayList<>();
// populate xs
}
return xs;
} Simple and safe. |
Upstream from jenkinsci/jenkins#3688