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

In the J2EE application, we use EJB2 in weblogic.

To avoid wasting time building the initial context and looking for the front-end EJB, I am considering a service locator pattern .

But after several searches on the Internet, I found that even if this template is often recommended for caching InitialContext, there are some negative reviews about EJB Home caching.

Questions:

  • Is it safe to cache an EJB Home search result?
  • What happens if one of my node clusters no longer works?
  • What happens if I install a new version of EJB without updating the service locator cache?
+4
source share
3 answers

Is it safe to cache the EJB Home lookup result?

Yes.

What happens if one of my node clusters no longer works?

If your server is configured for clustering / WLM, then the request should automatically switch to another server in the cluster. Routing information is encoded in the IOR stub.

What happens if I install a new version of EJB without updating the service locator cache?

Assuming you are updating the bean, not the components or home interfaces, then everything continues to work. EJBHome is actually a bean-free session, so the request can continue from the same server, if available, or to another server in the cluster, if not.

Note that injecting @EJB into EJB3 effectively encourages caching at home. (Although, admittedly, it also allows you to cache SFSB, although this is clearly not true, so @EJB may not be the best support for my claim :-)).

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

IMHO The goal of ServiceLocator in J2EE is to cache EJB Home and reduce costly JNDI searches. This is safe in Weblogic, because by default EJB Home is load balanced in the cluster, and this will automatically allow the transition to the next server.

This value is controlled by the value of home-is-clusterable 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 cache ? 

I did not even try to make such a change myself. However, I assume that part of your build / deployment, your Service Locator class will also be redistributed along with modifying your EJBs - and therefore make a new search?

If your client is not affected during changes to the EJB, the cached EJBHome will return the legacy link when you call the method on it. Therefore, you will have to force the client to upgrade.

+4
source

What happens if I install a new version of EJB without updating the service locator cache?

Once your application starts working, new installations should become much less common than requests for EJBHome.
Thus, your focus and concern should lie on frequent operations in real time, and not on transient development processes.
A factor in your design is the possibility of invalidating caches if necessary.

0
source

Source: https://habr.com/ru/post/1308218/


All Articles