我有以下的情况,在客户耳边应用程序有CDI @ApplicationScoped
Bean上的@PostConstruct
回调执行远程SLSB查找并缓存所获得的代理:蜻蜓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)中,换句话说,野蝇代理实现是线程安全的? – landal79
我已将更多信息添加到答案 –
它不是控制并发的@Singleton,它是会话bean。一个会话bean引用(您的代理)=>一个会话bean实例 –