J2EE client application hangs during startup finding JNDI intermittently
I couldn't find anything like this on the forum, so I'm posting hoping for help.
I'm working on a Spring-based client that runs on a number of machines, and communicates back to our J2EE container. That is to say that there is a Startup class with a main that creates the IoC container, loads a beans.xml file, and gets everything going. There may be dozens of these running on various machines.
The client is sometimes started before the server is ready to accept connections, and when it does, it hangs attempting to connect to the JNDI container. I am using a DefaultListableBeanFactory, and then wrapping preInstantiateSingletons() in a try/catch block, inside a while loop, so that it preInstantiates again if there's an exception. That seems to work, catching most failures to instantiate beans, but it doesn't catch this particular situation. Is there a better way to catch failures of beans to instantiate?
Here's the debug output from the area where it hangs:
2007-03-21 14:58:34,964 [DEBUG] org.springframework.beans.factory.support.DefaultL istableBeanFactory: Creating shared instance of singleton bean 'jndiTemplate'
2007-03-21 14:58:34,965 [DEBUG] org.springframework.beans.factory.support.DefaultL istableBeanFactory: Creating instance of bean 'jndiTemplate' with merged definition [Root bean: class [org.springframework.jndi.JndiTemplate]; scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [/home/bear/Services/trunk/Ibp/Hcs/beans.xml]]
2007-03-21 14:58:35,063 [DEBUG] org.springframework.beans.factory.support.DefaultL istableBeanFactory: Eagerly caching bean 'jndiTemplate' to allow for resolving potential circular references
2007-03-21 14:58:35,143 [DEBUG] org.springframework.beans.factory.support.DefaultL istableBeanFactory: Creating shared instance of singleton bean 'jmsDestinationResolver'
2007-03-21 14:58:35,143 [DEBUG] org.springframework.beans.factory.support.DefaultL istableBeanFactory: Creating instance of bean 'jmsDestinationResolver' with merged definition [Root bean: class [org.springframework.jms.support.destination.JndiDe stinationResolver]; scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [/home/bear/Services/trunk/Ibp/Hcs/beans.xml]]
2007-03-21 14:58:35,153 [DEBUG] org.springframework.beans.factory.support.DefaultL istableBeanFactory: Eagerly caching bean 'jmsDestinationResolver' to allow for resolving potential circular references
2007-03-21 14:58:35,153 [DEBUG] org.springframework.beans.factory.support.DefaultL istableBeanFactory: Returning cached instance of singleton bean 'jndiTemplate'
2007-03-21 14:58:35,155 [DEBUG] org.springframework.beans.factory.support.DefaultL istableBeanFactory: Creating shared instance of singleton bean 'jmsQueueConnectionFactory'
2007-03-21 14:58:35,155 [DEBUG] org.springframework.beans.factory.support.DefaultL istableBeanFactory: Creating instance of bean 'jmsQueueConnectionFactory' with merged definition [Root bean: class [org.springframework.jndi.JndiObjectFactoryBean]; scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [/home/bear/Services/trunk/Ibp/Hcs/beans.xml]]
2007-03-21 14:58:35,162 [DEBUG] org.springframework.beans.factory.support.DefaultL istableBeanFactory: Eagerly caching bean 'jmsQueueConnectionFactory' to allow for resolving potential circular references
2007-03-21 14:58:35,162 [DEBUG] org.springframework.beans.factory.support.DefaultL istableBeanFactory: Returning cached instance of singleton bean 'jndiTemplate'
2007-03-21 14:58:35,162 [DEBUG] org.springframework.beans.factory.support.DefaultL istableBeanFactory: Invoking afterPropertiesSet() on bean with name 'jmsQueueConnectionFactory'
2007-03-21 14:58:35,162 [DEBUG] org.springframework.jndi.JndiTemplate: Looking up JNDI object with name [UIL2ConnectionFactory]
2007-03-21 14:58:35,348 [DEBUG] org.jnp.interfaces.NamingContext: Failed to connect to ibp-isi:1099
javax.naming.CommunicationException: Failed to connect to server ibp-isi:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server ibp-isi:1099 [Root exception is java.net.ConnectException: Connection refused]]
at org.jnp.interfaces.NamingContext.getServer(NamingC ontext.java:269)
at org.jnp.interfaces.NamingContext.checkRef(NamingCo ntext.java:1385)
at org.jnp.interfaces.NamingContext.lookup(NamingCont ext.java:594)
at org.jnp.interfaces.NamingContext.lookup(NamingCont ext.java:587)
at javax.naming.InitialContext.lookup(InitialContext. java:351)
at org.springframework.jndi.JndiTemplate$1.doInContex t(JndiTemplate.java:124)
at org.springframework.jndi.JndiTemplate.execute(Jndi Template.java:86)
at org.springframework.jndi.JndiTemplate.lookup(JndiT emplate.java:122)
at org.springframework.jndi.JndiTemplate.lookup(JndiT emplate.java:147)
at org.springframework.jndi.JndiLocatorSupport.lookup (JndiLocatorSupport.java:91)
at org.springframework.jndi.JndiObjectLocator.lookup( JndiObjectLocator.java:101)
at org.springframework.jndi.JndiObjectFactoryBean.loo kupWithFallback(JndiObjectFactoryBean.java:164)
at org.springframework.jndi.JndiObjectFactoryBean.aft erPropertiesSet(JndiObjectFactoryBean.java:151)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1118)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1085)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:429)
at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 50)
at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:141)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:247)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:161)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:270)
at com.ingrid.ibp.hcs.server.Startup.main(Startup.jav a:88)
Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server ibp-isi:1099 [Root exception is java.net.ConnectException: Connection refused]
at org.jnp.interfaces.NamingContext.getServer(NamingC ontext.java:243)
... 21 more
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl .java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSoc ketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.j ava:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.j ava:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at java.net.Socket.<init>(Socket.java:366)
at java.net.Socket.<init>(Socket.java:266)
at org.jnp.interfaces.TimedSocketFactory.createSocket (TimedSocketFactory.java:84)
at org.jnp.interfaces.TimedSocketFactory.createSocket (TimedSocketFactory.java:77)
at org.jnp.interfaces.NamingContext.getServer(NamingC ontext.java:239)
... 21 more
As well as the relevant part of the beans.xml:
HTML Code:
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
<prop key="java.naming.provider.url">localhost</prop>
<prop key="java.naming.factory.url.pkgs">org.jnp.interfaces:org.jboss.naming</prop>
</props>
</property>
</bean>
<!-- JMS Destination Resolver -->
<bean id="jmsDestinationResolver"
class="org.springframework.jms.support.destination.JndiDestinationResolver">
<property name="jndiTemplate" ref="jndiTemplate"/>
<property name="cache" value="true"/>
</bean>
<bean id="jmsQueueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="jndiTemplate"/>
<property name="jndiName" value="UIL2ConnectionFactory"/>
</bean>
<bean id="inboundSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="jndiTemplate"/>
<property name="jndiName" value="queue/inqueue"/>
</bean>