Skip to content

Commit

Permalink
Merge pull request #478 from davoustp/contention-in-singleton-injecti…
Browse files Browse the repository at this point in the history
…on-2.6.x

[WW-5121] Fix: remove contention during Scope.SINGLETON injection
  • Loading branch information
yasserzamani committed Mar 23, 2021
2 parents ca99c7b + cb2c67e commit 49a4d6d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions core/src/main/java/com/opensymphony/xwork2/inject/Scope.java
Expand Up @@ -44,15 +44,17 @@ <T> InternalFactory<? extends T> scopeFactory(Class<T> type, String name,
@Override
<T> InternalFactory<? extends T> scopeFactory(Class<T> type, String name, final InternalFactory<? extends T> factory) {
return new InternalFactory<T>() {
T instance;
volatile T instance;

public T create(InternalContext context) {
synchronized (context.getContainer()) {
if (instance == null) {
instance = InitializableFactory.wrapIfNeeded(factory).create(context);
if (instance == null) {
synchronized (context.getContainer()) {
if (instance == null) {
instance = InitializableFactory.wrapIfNeeded(factory).create(context);
}
}
return instance;
}
return instance;
}

@Override
Expand Down

0 comments on commit 49a4d6d

Please sign in to comment.