This is an automated email from the ASF dual-hosted git repository. yasserzamani pushed a commit to branch struts-2-5-x in repository https://gitbox.apache.org/repos/asf/struts.git
The following commit(s) were added to refs/heads/struts-2-5-x by this push: new ce8b75d [WW-5121] Fix: remove contention during Scope.SINGLETON injection new 7e912a2 Merge pull request #479 from davoustp/contention-in-singleton-injection-2.5.x ce8b75d is described below commit ce8b75de58cca46dade40d76d5d421be5ff808ba Author: Pascal Davoust <pascal.davo...@eptica.com> AuthorDate: Mon Mar 22 09:40:02 2021 +0100 [WW-5121] Fix: remove contention during Scope.SINGLETON injection --- core/src/main/java/com/opensymphony/xwork2/inject/Scope.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/com/opensymphony/xwork2/inject/Scope.java b/core/src/main/java/com/opensymphony/xwork2/inject/Scope.java index 86592bb..3974d6c 100644 --- a/core/src/main/java/com/opensymphony/xwork2/inject/Scope.java +++ b/core/src/main/java/com/opensymphony/xwork2/inject/Scope.java @@ -44,15 +44,17 @@ public enum Scope { @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