提交 09ffd991 编写于 作者: K Kohsuke Kawaguchi

touch up. jobNames is a collection that does require a synchronization.

But the general direction of reducing the size of the lock is correct.
上级 ed0a6157
...@@ -24,8 +24,6 @@ ...@@ -24,8 +24,6 @@
*/ */
package hudson.model; package hudson.model;
import com.infradna.tool.bridge_method_injector.BridgeMethodsAdded;
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import hudson.Extension; import hudson.Extension;
import hudson.Util; import hudson.Util;
import hudson.model.Descriptor.FormException; import hudson.model.Descriptor.FormException;
...@@ -34,12 +32,12 @@ import hudson.util.DescribableList; ...@@ -34,12 +32,12 @@ import hudson.util.DescribableList;
import hudson.util.FormValidation; import hudson.util.FormValidation;
import hudson.views.ListViewColumn; import hudson.views.ListViewColumn;
import hudson.views.ViewJobFilter; import hudson.views.ViewJobFilter;
import jenkins.model.Jenkins;
import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter; import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse; import org.kohsuke.stapler.StaplerResponse;
import javax.annotation.concurrent.GuardedBy;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -60,6 +58,7 @@ public class ListView extends View implements Saveable { ...@@ -60,6 +58,7 @@ public class ListView extends View implements Saveable {
/** /**
* List of job names. This is what gets serialized. * List of job names. This is what gets serialized.
*/ */
@GuardedBy("this")
/*package*/ final SortedSet<String> jobNames = new TreeSet<String>(CaseInsensitiveComparator.INSTANCE); /*package*/ final SortedSet<String> jobNames = new TreeSet<String>(CaseInsensitiveComparator.INSTANCE);
private DescribableList<ViewJobFilter, Descriptor<ViewJobFilter>> jobFilters; private DescribableList<ViewJobFilter, Descriptor<ViewJobFilter>> jobFilters;
...@@ -135,7 +134,11 @@ public class ListView extends View implements Saveable { ...@@ -135,7 +134,11 @@ public class ListView extends View implements Saveable {
* concurrent modification issue. * concurrent modification issue.
*/ */
public List<TopLevelItem> getItems() { public List<TopLevelItem> getItems() {
SortedSet<String> names = new TreeSet<String>(jobNames); SortedSet<String> names;
synchronized (this) {
names = new TreeSet<String>(jobNames);
}
if (includePattern != null) { if (includePattern != null) {
for (Item item : getOwnerItemGroup().getItems()) { for (Item item : getOwnerItemGroup().getItems()) {
...@@ -146,6 +149,7 @@ public class ListView extends View implements Saveable { ...@@ -146,6 +149,7 @@ public class ListView extends View implements Saveable {
} }
} }
Boolean statusFilter = this.statusFilter; // capture the value to isolate us from concurrent update
List<TopLevelItem> items = new ArrayList<TopLevelItem>(names.size()); List<TopLevelItem> items = new ArrayList<TopLevelItem>(names.size());
for (String n : names) { for (String n : names) {
TopLevelItem item = getOwnerItemGroup().getItem(n); TopLevelItem item = getOwnerItemGroup().getItem(n);
...@@ -167,7 +171,7 @@ public class ListView extends View implements Saveable { ...@@ -167,7 +171,7 @@ public class ListView extends View implements Saveable {
return items; return items;
} }
public boolean contains(TopLevelItem item) { public synchronized boolean contains(TopLevelItem item) {
return jobNames.contains(item.getName()); return jobNames.contains(item.getName());
} }
...@@ -177,7 +181,9 @@ public class ListView extends View implements Saveable { ...@@ -177,7 +181,9 @@ public class ListView extends View implements Saveable {
* @since 1.389 * @since 1.389
*/ */
public void add(TopLevelItem item) throws IOException { public void add(TopLevelItem item) throws IOException {
jobNames.add(item.getName()); synchronized (this) {
jobNames.add(item.getName());
}
save(); save();
} }
...@@ -219,10 +225,12 @@ public class ListView extends View implements Saveable { ...@@ -219,10 +225,12 @@ public class ListView extends View implements Saveable {
*/ */
@Override @Override
protected void submit(StaplerRequest req) throws ServletException, FormException, IOException { protected void submit(StaplerRequest req) throws ServletException, FormException, IOException {
jobNames.clear(); synchronized (this) {
for (TopLevelItem item : getOwnerItemGroup().getItems()) { jobNames.clear();
if(req.getParameter(item.getName())!=null) for (TopLevelItem item : getOwnerItemGroup().getItems()) {
jobNames.add(item.getName()); if(req.getParameter(item.getName())!=null)
jobNames.add(item.getName());
}
} }
if (req.getParameter("useincluderegex") != null) { if (req.getParameter("useincluderegex") != null) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册