提交 1584c350 编写于 作者: K kohsuke

eliminating a lock, at the expense of potentially inefficient computation.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@7562 71c3de6d-444a-0410-be80-ed276b4c234a
上级 102cc762
...@@ -279,7 +279,7 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node, ...@@ -279,7 +279,7 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node,
*/ */
private transient final ConcurrentHashMap<String,Label> labels = new ConcurrentHashMap<String,Label>(); private transient final ConcurrentHashMap<String,Label> labels = new ConcurrentHashMap<String,Label>();
private transient Set<Label> labelSet; private transient Set<Label> labelSet;
private transient Set<Label> dynamicLabels = null; private transient volatile Set<Label> dynamicLabels = null;
public transient final ServletContext servletContext; public transient final ServletContext servletContext;
...@@ -1189,22 +1189,22 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node, ...@@ -1189,22 +1189,22 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node,
*/ */
public Set<Label> getDynamicLabels() { public Set<Label> getDynamicLabels() {
if (dynamicLabels == null) { if (dynamicLabels == null) {
synchronized (this) { // in the worst cast, two threads end up doing the same computation twice,
Computer comp = getComputer(""); // but that won't break the semantics.
if (dynamicLabels == null) { // OTOH, not locking prevents dead-lock. See #1390
dynamicLabels = new HashSet<Label>(); Set<Label> r = new HashSet<Label>();
if (comp != null) { Computer comp = getComputer("");
VirtualChannel channel = comp.getChannel(); if (comp != null) {
if (channel != null) { VirtualChannel channel = comp.getChannel();
for (DynamicLabeler labeler : LabelFinder.LABELERS) { if (channel != null) {
for (String label : labeler.findLabels(channel)) { for (DynamicLabeler labeler : LabelFinder.LABELERS) {
dynamicLabels.add(getLabel(label)); for (String label : labeler.findLabels(channel)) {
} r.add(getLabel(label));
}
} }
} }
} }
} }
dynamicLabels = r;
} }
return dynamicLabels; return dynamicLabels;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册