Feb 25th, 2009, 06:40 AM
Why does JndiTemplate creates new InitialContext all the time?
accessing EJB3 Stateless Session Beans using Spring 2.5.6 from a Swing Rich Client multiple jndi-lookups connect to different managed servers of a WeblogicServer 10.0 cluster.
This maybe because of our DNS rotation which - on each request - returns "the next" server on a list. I think this is supposed to balance the load of the initial connect of a client onto the servers. (The same list of servers is configured as a cluster in the WLS admin console.)
The lookup in the client is performed using a (slightly modified) SimpleRemoteStatelessSessionProxyFactoryBean referencing a JndiTemplate.
Trying to determine the cause of multiple server connections I discovered that a new InitialContext is created for each jndi lookup. My attempt of a simple caching (in a subclass of JndiTemplate) was not sufficient since the context is closed after a lookup.
Question: Why is this?
Reusing one InitialContext for every jndi-lookup may - in my case - ensure that one client does not directly use connections to more than one server. Load Balancing (at least after the initial connect) and automatic failover - in my understanding - should be managed by weblogic-classes on client and server (which doesn't really work at my place, but that is another issue).
(If one needs a new InitialContext every time one could declare the JndiTemplate with scope="prototype", I would have thought.)
Thanks in advance for any hints.
Tags for this Thread