mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-11 19:16:42 +00:00
Fixed a possible race condition during Hudson start up.
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@34294 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
4abc357d33
commit
02fbfd9ed5
2 files changed
+22
-3
No files matched your search
@@ -24,7 +24,6 @@
|
||||
|
||||
package hudson;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
@@ -33,7 +32,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class Lookup {
|
||||
private final Map<Class,Object> data = new ConcurrentHashMap<Class,Object>();
|
||||
private final ConcurrentHashMap<Class,Object> data = new ConcurrentHashMap<Class,Object>();
|
||||
|
||||
public <T> T get(Class<T> type) {
|
||||
return type.cast(data.get(type));
|
||||
@@ -42,4 +41,17 @@ public class Lookup {
|
||||
public <T> T set(Class<T> type, T instance) {
|
||||
return type.cast(data.put(type,instance));
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrites the value only if the current value is null.
|
||||
*
|
||||
* @return
|
||||
* If the value was null, return the {@code instance} value.
|
||||
* Otherwise return the current value, which is non-null.
|
||||
*/
|
||||
public <T> T setIfNull(Class<T> type, T instance) {
|
||||
Object o = data.putIfAbsent(type, instance);
|
||||
if (o!=null) return type.cast(o);
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user