Skip to content

Commit

Permalink
Merge pull request #13 from synopsys-arc-oss/JENKINS_21044_fix
Browse files Browse the repository at this point in the history
[FIXED JENKINS-21044] - Throttling blocks the Jenkins queue
  • Loading branch information
abayer committed Mar 7, 2014
2 parents dc16282 + c453516 commit 70107b4
Showing 1 changed file with 23 additions and 10 deletions.
Expand Up @@ -91,13 +91,13 @@ public Object readResolve() {
@Override protected void setOwner(AbstractProject<?,?> owner) {
super.setOwner(owner);
if (throttleEnabled && categories != null) {
Map<String,Map<ThrottleJobProperty,Void>> propertiesByCategory = ((DescriptorImpl) getDescriptor()).propertiesByCategory;
synchronized (propertiesByCategory) {
DescriptorImpl descriptor = (DescriptorImpl) getDescriptor();
synchronized (descriptor.propertiesByCategoryLock) {
for (String c : categories) {
Map<ThrottleJobProperty,Void> properties = propertiesByCategory.get(c);
Map<ThrottleJobProperty,Void> properties = descriptor.propertiesByCategory.get(c);
if (properties == null) {
properties = new WeakHashMap<ThrottleJobProperty,Void>();
propertiesByCategory.put(c, properties);
descriptor.propertiesByCategory.put(c, properties);
}
properties.put(this, null);
}
Expand Down Expand Up @@ -135,9 +135,9 @@ static List<AbstractProject<?,?>> getCategoryProjects(String category) {
assert category != null && !category.equals("");
List<AbstractProject<?,?>> categoryProjects = new ArrayList<AbstractProject<?, ?>>();
Collection<ThrottleJobProperty> properties;
Map<String,Map<ThrottleJobProperty,Void>> propertiesByCategory = Jenkins.getInstance().getDescriptorByType(DescriptorImpl.class).propertiesByCategory;
synchronized (propertiesByCategory) {
Map<ThrottleJobProperty,Void> _properties = propertiesByCategory.get(category);
DescriptorImpl descriptor = Jenkins.getInstance().getDescriptorByType(DescriptorImpl.class);
synchronized (descriptor.propertiesByCategoryLock) {
Map<ThrottleJobProperty,Void> _properties = descriptor.propertiesByCategory.get(category);
properties = _properties != null ? new ArrayList<ThrottleJobProperty>(_properties.keySet()) : Collections.<ThrottleJobProperty>emptySet();
}
for (ThrottleJobProperty t : properties) {
Expand Down Expand Up @@ -165,13 +165,26 @@ public static final class DescriptorImpl extends JobPropertyDescriptor {
private List<ThrottleCategory> categories;

/** Map from category names, to properties including that category. */
private Map<String,Map<ThrottleJobProperty,Void>> propertiesByCategory = new HashMap<String,Map<ThrottleJobProperty,Void>>();
private transient Map<String,Map<ThrottleJobProperty,Void>> propertiesByCategory
= new HashMap<String,Map<ThrottleJobProperty,Void>>();
/** A sync object for {@link #propertiesByCategory} */
private final transient Object propertiesByCategoryLock = new Object();

public DescriptorImpl() {
super(ThrottleJobProperty.class);
load();
synchronized(propertiesByCategoryLock) {
load();
// Explictly handle the persisted data from the version 1.8.1
if (propertiesByCategory == null) {
propertiesByCategory = new HashMap<String,Map<ThrottleJobProperty,Void>>();
}
if (!propertiesByCategory.isEmpty()) {
propertiesByCategory.clear();
save(); // Save the configuration to remove obsolete data
}
}
}

@Override
public String getDisplayName() {
return "Throttle Concurrent Builds";
Expand Down

0 comments on commit 70107b4

Please sign in to comment.