J2EE/EJB +服务定位器:缓存 EJB Home 查找结果安全吗?

发布于 2024-08-30 23:00:17 字数 408 浏览 4 评论 0原文

在 J2EE 应用程序中,我们在 weblogic 中使用 EJB2。

为了避免浪费时间构建初始上下文和查找 EJB Home 接口,我正在考虑 服务定位器模式

但在网络上进行了一些搜索后,我发现即使这种模式经常被推荐用于 InitialContext 缓存,但对于 EJB Home 缓存也存在一些负面意见。

问题:

  • 缓存 EJB Home 查找结果安全吗?
  • 如果我的一个集群节点不再工作会发生什么?
  • 如果我安装新版本的 EJB 而不刷新服务定位器的缓存,会发生什么情况?

In a J2EE application, we are using EJB2 in weblogic.

To avoid losing time building the initial context and looking up EJB Home interface, I'm considering the Service Locator Pattern.

But after a few search on the web I found that even if this pattern is often recommended for the InitialContext caching, there are some negative opinion about the EJB Home caching.

Questions:

  • Is it safe to cache EJB Home lookup result ?
  • What will happen if one my cluster node is no more working ?
  • What will happen if I install a new version of the EJB without refreshing the service locator's cache ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

知你几分 2024-09-06 23:00:17

缓存 EJB Home 查找是否安全
结果?

是的。

如果我的集群中有一个会发生什么
节点不再工作?

如果您的服务器配置为集群/WLM,则请求应静默故障转移到集群中的另一台服务器。路由信息被编码在存根 IOR 中。

如果我安装新的会发生什么
无需刷新的EJB版本
服务定位器的缓存?

假设您更新 bean 而不是组件或 home 接口,那么一切都会继续工作。 EJBHome 实际上是一个无状态会话 bean,因此可以从同一台服务器(如果可用)继续访问该请求,如果不可用,则可以在集群中的不同服务器上继续访问该请求。

请注意,EJB3 中的 @EJB 注入有效地鼓励了家庭缓存。 (不过,无可否认,它也允许 SFSB 缓存,尽管这显然是不正确的,所以 @EJB 可能不是我的主张的最佳支持:-))。

Is it safe to cache EJB Home lookup
result ?

Yes.

What will happen if one my cluster
node is no more working ?

If your server is configured for clustering/WLM, then the request should silently failover to another server in the cluster. The routing information is encoded in the stub IOR.

What will happen if I install a new
version of the EJB without refreshing
the service locator's cache ?

Assuming you update the bean and not the component or home interfaces, then everything continues to work. EJBHome is effectively a stateless session bean, so the request can continue to be accessed from the same server if available or on a different server in the cluster if not.

Note that the @EJB injection in EJB3 effectively encourages home caching. (Though, admittedly, it also allows SFSB caching even though this is clearly incorrect, so perhaps @EJB isn't the best support of my claim :-)).

疏忽 2024-09-06 23:00:17
Is it safe to cache EJB Home lookup result ?
What will happen if one my cluster node is no more working ? 

恕我直言,J2EE 中 ServiceLocator 的目的是缓存 EJB Home 并减少昂贵的 JNDI 查找。它在 Weblogic 上是安全的,因为默认情况下 EJB Home 在集群中进行负载平衡,这将自动允许故障转移到下一个服务器。

该值由 weblogic-ejb-jar.xml 中的 home-is-clusterable 值控制,记录在 此处,默认为 true

What will happen if I install a new version of the EJB without refreshing 
the service locator's cache ?

我自己还没有尝试过做这样的改变。但是,我猜测作为构建/部署的一部分,您的服务定位器类也会随着 EJB 的更改而重新部署 - 从而进行新的查找?

如果您的客户端在 EJB 更改期间不受影响,那么当您对其调用方法时,缓存的 EJBHome 将返回过时的引用。所以你必须强制客户端刷新。

Is it safe to cache EJB Home lookup result ?
What will happen if one my cluster node is no more working ? 

IMHO the purpose of ServiceLocator within J2EE is to cache EJB Home and reduce expensive JNDI look ups. It is safe on Weblogic since by default the EJB Home is load balanced across the cluster, and this will automatically allow failover to the next server.

This value is controlled by the home-is-clusterable value in weblogic-ejb-jar.xml, documented here which defaults to true.

What will happen if I install a new version of the EJB without refreshing 
the service locator's cache ?

I havent tried doing such a change myself. However, I'm guessing as part of your build/deploy, your Service Locator class would also get redeployed along with a change to your EJBs - and thus do a fresh lookup?

If your client is unaffected during the changes to the EJB, then the cached EJBHome will return a stale reference when you call a method on it. So you will have to force the client to be refreshed.

俏︾媚 2024-09-06 23:00:17

如果我安装新的会发生什么
无需刷新的EJB版本
服务定位器的缓存?

一旦您的应用程序上线,新安装的频率应该比 EJBHome 的请求要低得多。
因此,您的重点和关注点应该在于频繁的实时操作,而不是短暂的开发操作。
在您的设计中考虑到必要时使缓存失效的能力。

What will happen if I install a new
version of the EJB without refreshing
the service locator's cache ?

Once your application goes live, new installations should become much less frequent than requests for an EJBHome.
So your focus and concern should lie with the frequent live operations, rather than the transient development operations.
Factor into your design the ability to invalidate caches when necessary.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文