Skip to content

Commit

Permalink
[JENKINS-45244] Avoid locking every time getActions is called (#2933)
Browse files Browse the repository at this point in the history
* [JENKINS-45244] Avoid locking every time getActions is called

* [JENKINS-45244] - Remove initializer

* Add comment clarifying that the actions must be volatile
  • Loading branch information
alvarolobato authored and oleg-nenashev committed Aug 5, 2017
1 parent 6e652ae commit 1c8ed8e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions core/src/main/java/hudson/model/Actionable.java
Expand Up @@ -74,12 +74,15 @@ public abstract class Actionable extends AbstractModelObject implements ModelObj
@Deprecated
@Nonnull
public List<Action> getActions() {
synchronized (this) {
if(actions == null) {
actions = new CopyOnWriteArrayList<Action>();
//this double checked synchronization is only safe if the field 'actions' is volatile
if (actions == null) {
synchronized (this) {
if (actions == null) {
actions = new CopyOnWriteArrayList<Action>();
}
}
return actions;
}
return actions;
}

/**
Expand Down

0 comments on commit 1c8ed8e

Please sign in to comment.