Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

J2EE/EJB + service locator: is it safe to cache EJB Home lookup result?

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 ?
like image 331
Guillaume Avatar asked Feb 28 '23 03:02

Guillaume


1 Answers

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 :-)).

like image 152
Brett Kail Avatar answered Mar 01 '23 15:03

Brett Kail