Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Commit

Permalink
Prevent deadlock between WebApplicationImpl and EJBInjectionInterceptor.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaodong-xie authored and pavelbucek committed Mar 11, 2016
1 parent 041bb48 commit 3f1fa74
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2010-2011 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010-2016 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -39,16 +39,19 @@
*/
package com.sun.jersey.server.impl.ejb;

import com.sun.jersey.core.spi.component.ComponentScope;
import com.sun.jersey.core.spi.component.ioc.IoCComponentProcessor;
import com.sun.jersey.core.spi.component.ioc.IoCComponentProcessorFactory;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicBoolean;

import javax.annotation.ManagedBean;
import javax.annotation.PostConstruct;
import javax.interceptor.InvocationContext;
import javax.ws.rs.ext.Provider;

import com.sun.jersey.core.spi.component.ComponentScope;
import com.sun.jersey.core.spi.component.ioc.IoCComponentProcessor;
import com.sun.jersey.core.spi.component.ioc.IoCComponentProcessorFactory;

final class EJBInjectionInterceptor {

private IoCComponentProcessorFactory cpf;
Expand All @@ -60,18 +63,25 @@ public void setFactory(IoCComponentProcessorFactory cpf) {
this.cpf = cpf;
}

private final AtomicBoolean initializing = new AtomicBoolean(false);

@PostConstruct
private void init(final InvocationContext context) throws Exception {
if (cpf == null) {
// Not initialized
return;
}

boolean setInitializing = initializing.compareAndSet(false, true);
if (!setInitializing) {
return;
}
final Object beanInstance = context.getTarget();
final IoCComponentProcessor icp = get(beanInstance.getClass());
if (icp != null)
if (icp != null) {
icp.postConstruct(beanInstance);

}

// Invoke next interceptor in chain
context.proceed();
}
Expand Down

0 comments on commit 3f1fa74

Please sign in to comment.