diff --git a/exo.kernel.container/src/main/java/org/exoplatform/container/component/RequestLifeCycle.java b/exo.kernel.container/src/main/java/org/exoplatform/container/component/RequestLifeCycle.java index 58151a9a1..c2e266916 100644 --- a/exo.kernel.container/src/main/java/org/exoplatform/container/component/RequestLifeCycle.java +++ b/exo.kernel.container/src/main/java/org/exoplatform/container/component/RequestLifeCycle.java @@ -35,7 +35,7 @@ public class RequestLifeCycle { /** The current stack. */ - private static ThreadLocal current = new ThreadLocal(); + private static ThreadLocal current = new ThreadLocal<>(); /** The components of this life cycle. */ private List components; @@ -59,7 +59,7 @@ void doBegin() IdentityHashMap doEnd() { - IdentityHashMap result = new IdentityHashMap(); + IdentityHashMap result = new IdentityHashMap<>(); // for (ComponentRequestLifecycle componentRLF : components) @@ -152,26 +152,23 @@ public static void begin(ExoContainer container) * @throws IllegalStateException if no container life cycle is associated with this thread * @return the result map */ - public static Map end() throws IllegalStateException - { - RequestLifeCycleStack lf = current.get(); - if (lf == null) - { - throw new IllegalStateException(); - } - Map result = lf.end(); - if (lf.isEmpty()) - { - current.set(null); - } - return result; + public static Map end() throws IllegalStateException { + RequestLifeCycleStack lf = current.get(); + if (lf == null) { + throw new IllegalStateException(); + } + Map result = lf.end(); + if (lf.isEmpty()) { + current.remove(); + } + return result; } - protected void restartTransaction() { + public static void restartTransaction() { restartTransaction(ExoContainerContext.getCurrentContainer()); } - protected void restartTransaction(ExoContainer container) { + public static void restartTransaction(ExoContainer container) { int i = 0; // Close transactions until no encapsulated transaction boolean success = true; @@ -202,7 +199,7 @@ public static boolean isStarted(ComponentRequestLifecycle lifeCycle) { throw new IllegalArgumentException("The lifeCycle cannot be null"); } RequestLifeCycleStack lf = current.get(); - return lf == null ? false : lf.isStarted(lifeCycle); + return lf != null && lf.isStarted(lifeCycle); } /** @@ -217,6 +214,6 @@ public static boolean isStarted(ExoContainer container, boolean local){ throw new IllegalArgumentException("The container cannot be null"); } RequestLifeCycleStack lf = current.get(); - return lf== null ? false : lf.isStarted(container, local); - } + return lf != null && lf.isStarted(container, local); + } }