I have a situation where in my web layer, I do a remote EJB lookup and cache the initial context. Now the remote EJB is deployed in a WAS cluster. so if the remote ejb is deployed across server1,server2 and server3 and let us say the first time, the initial context pointing to server1 is cached.
After this server1 goes down but other servers are still up. But because the initial context is cached, the ejb calls fail.
Now the simple solution is to remove the cache and do a fresh lookup every time. But that would degrade performance. Is there a way to have the best of both worlds here…reliability and also performance?
The list of bootstrap servers in the
corbaloc:provider URL is only used when theInitialContextis constructed. During the construction of the context, the client gets a list of servers that can answer lookups for that context, and only that list is used afterwards. If the bootstrap servers in the provider URL are cluster members, then theInitialContextwill continue to work as long as at least one cluster member is running. Therefore theInitialContextcan be safely cached.Note that things are different if the bootstrap servers in the provider URL are not cluster members, but node agents. In that case, the
InitialContextreferes to a context specific to a single node agent and lookups will fail when that node agent is down. This is the case even if multiple node agents are specified in the provider URL: one of the node agents is chosen during construction of theInitialContextand the selection will not change afterwards.