私は次のような状況を持っているが、クライアントの耳のアプリケーションに@PostConstruct
コールバックにリモートSLSB検索を実行し、得られたプロキシをキャッシュCDI @ApplicationScoped
Beanがあります: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
を使用するのに最適ですか?事前
ありがとう、私の疑問は、同時にアクセスされるシングルトンBean(CDI ApplicationScoped)にwildflyプロキシリファレンスを格納するのが安全かどうか、つまりワイルドフックプロキシの実装がスレッドセーフであるかどうかです。 – landal79
私は答えにさらに多くの情報を追加しました –
同時性を制御するのは@Singletonではなく、セッションBeanです。 1つのセッションBeanリファレンス(プロキシ)=> 1つのセッションBeanインスタンス –