From 23f676c1b1b29cf71e49cd0e0073af366e7cb723 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Mon, 3 Jul 2023 14:09:39 +0300 Subject: [PATCH] Revert "Remove unnecessary synchronization when creating Resource instances" --- .../reactive/server/handlers/InstanceHandler.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/InstanceHandler.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/InstanceHandler.java index c30585e4b5167..e988e33a93742 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/InstanceHandler.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/InstanceHandler.java @@ -10,6 +10,7 @@ public class InstanceHandler implements ServerRestHandler { * CDI Manages the lifecycle * */ + private volatile Object instance; private final BeanFactory factory; public InstanceHandler(BeanFactory factory) { @@ -18,7 +19,14 @@ public InstanceHandler(BeanFactory factory) { @Override public void handle(ResteasyReactiveRequestContext requestContext) throws Exception { - requestContext.requireCDIRequestScope(); - requestContext.setEndpointInstance(factory.createInstance().getInstance()); + if (instance == null) { + synchronized (this) { + if (instance == null) { + requestContext.requireCDIRequestScope(); + instance = factory.createInstance().getInstance(); + } + } + } + requestContext.setEndpointInstance(instance); } }