Skip to content

Commit

Permalink
Merge pull request #34476 from quarkusio/revert-34339-rr-instance
Browse files Browse the repository at this point in the history
Revert "Remove unnecessary synchronization when creating Resource instances
  • Loading branch information
geoand authored Jul 4, 2023
2 parents 468397a + 23f676c commit 5d1fc20
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class InstanceHandler implements ServerRestHandler {
* CDI Manages the lifecycle
*
*/
private volatile Object instance;
private final BeanFactory<Object> factory;

public InstanceHandler(BeanFactory<Object> factory) {
Expand All @@ -18,7 +19,14 @@ public InstanceHandler(BeanFactory<Object> 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);
}
}

0 comments on commit 5d1fc20

Please sign in to comment.