I have the following situation, in a client ear application there is CDI `@ApplicationScoped` bean which performs a remote SLSB lookup on `@PostConstruct` callback and caches the obtained proxy:
@ApplicationScoped @Typed({ ServiceInterface.class }) public class RemoteServiceProxy implements ServiceInterface { /** * Remote service. */ private RemoteService remoteService; @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); } } ... }
I would like to know if the cached proxy in the field `remoteService` is thread-safe, so the `RemoteServiceProxy` can be annotated with `@ApplicationScoped`, or I have to perform a new proxy lookup for each invocation? Or is a best to use `@Stateless`?
Thanks in advance