2016-11-17 3 views
2

나는 클라이언트 귀 응용 프로그램에서 CDI는 @PostConstruct 콜백에서 원격 SLSB 조회를 수행하고, 얻어진 프록시 캐시 @ApplicationScoped 콩 다음과 같은 상황이있다 :Wildfly 8 : ejb 원격 프록시 스레드가 안전합니까?

@ApplicationScoped 
@Typed({ ServiceInterface.class }) 
public class RemoteServiceProxy implements ServiceInterface 
{ 
    /** 
    * Remote service. 
    */ 
    private RemoteService remoteService; 

    /** 
    * Default constructor. 
    */ 
    public RemoteServiceProxy() 
    { 
     super(); 
    } 

    /** 
    * PostConstruct callback. 
    * 
    * @throws RuntimeException 
    *    Error while looking up remote proxy 
    */ 
    @PostConstruct 
    protected void onPostConstruct() 
    { 
     try 
     { 
      remoteService = serviceLocator.lookup(ActivityRemoteEntityService.class); 

      Properties jndiProps = new Properties(); 
      jndiProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); 
      jndiProps.put(Context.PROVIDER_URL, "http-remoting://localhost:8080"); 
      jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); 
      jndiProps.put("jboss.naming.client.ejb.context", "true"); 

      Context context = new InitialContext(jndiProps); 

      remoteService = (RemoteService) context.lookup(
       "application.backend/application.backend-service//RemoteServiceImpl!com.application.remote.RemoteService"); 
     } catch (NamingException e) 
     { 
      throw new RuntimeException(e); 
     } 
    } 

    ... 

} 

내가 알고 싶습니다을 경우 캐시 프록시에서 remoteService 필드는 스레드로부터 안전하므로 RemoteServiceProxy@ApplicationScoped이라는 주석을 달거나 호출 할 때마다 새로운 프록시 조회를 수행해야합니까? 또는 @Stateless을 사용하는 것이 가장 좋습니다? 사전에

감사

답변

1

는 EJB 3.2 사양이있는 말을 다음

세션 빈에 3.4.9 동시 액세스가 참고

세션 빈 참조를 취득 허용하고 복수의 thread로부터 동시에 같은 참조 객체를 호출하려고합니다. 그러나 각 스레드에서 결과로 나타나는 클라이언트 동작은 대상 bean의 동시성 의미에 따라 달라집니다. 세션 빈의 동시성 동작에 대한 자세한 내용은 4.3.13 절과 4.8.5 절을 참조하십시오.

§4.3.13은 기본적으로 세션 빈에 대한 동시 호출이 컨테이너에 의해 직렬화된다고 말합니다.

§4.8.5는 싱글 톤 세션 빈에 대한 동시 액세스를 둘러싼 의미를 설명합니다.

따라서 원격 프록시는 본질적으로 "세션 빈 참조"에 필요한 의미를 따라야하므로 스레드로부터 안전해야합니다.

그런 언급을 @Singleton EJB에 저장하면이 참조는 한 번에 하나의 메소드 호출 만 처리 할 수 ​​있습니다 (그러한 호출은 "직렬화"되기 때문에). 이렇게하면 응용 프로그램에서 바람직하지 않은 병목 현상이 발생할 수 있습니다.

+0

답변을 주셔서 감사합니다, 그것은 의심스럽지 만 singleton bean (CDI ApplicationScoped)에 wildfly 프록시 참조를 저장하는 것이 안전합니다. 즉, 동시에 액세스되는 wildfly 프록시 구현은 thread-safe입니까? – landal79

+0

응답에 더 많은 정보를 추가했습니다 –

+0

동시성을 제어하는 ​​@Singleton이 아니라 세션 빈입니다. 하나의 세션 빈 참조 (프록시) => 하나의 세션 빈 인스턴스 –

관련 문제