简体   繁体   English

如何在EJB 3.1中缓存EJB远程接口?

[英]How to cache the EJB remote interface in EJB 3.1?

Is there any way to Cache the reference to remote EJB at client side? 有没有办法在客户端缓存对远程EJB的引用?

In EJB 2.x it is achieved by caching the EJBHome . 在EJB 2.x中,它是通过缓存EJBHome来实现的。

Do we have any similar feature available in EJB 3.x to cache the EJB Remote Interface which will provide new instance of EJB (Stateless session bean) every time it is used? 我们是否在EJB 3.x中有任何类似的功能来缓存EJB Remote Interface ,它将在每次使用时提供EJB(Stateless会话bean)的新实例? (In EJB 2.x we get new instance of EJB when we call create() method on EJBHome ) (在EJB 2.x中 ,当我们在EJBHome上调用create()方法时,我们得到了EJB的新实例)

You don't need a new instance of the stateless session bean because they're stateless. 您不需要无状态会话bean的新实例,因为它们是无状态的。 The reference you have in the client is a stateless proxy, so the EJB container will obtain a new (or pooled) instance of the stateless bean for each request, and it will destroy (or return to the pool) the instance when the method completes. 您在客户端中的引用是无状态代理,因此EJB容器将为每个请求获取无状态bean的新(或池)实例,并且当方法完成时它将销毁(或返回池)实例。 For EJB 3, you can simply cache the result of the lookup. 对于EJB 3,您只需缓存查找结果即可。 This is implicitly encouraged by the @EJB field injection, which encourages you to store the EJB reference in a simple field. @EJB字段注入暗示鼓励这一点,它鼓励您将EJB引用存储在一个简单的字段中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM