Search code examples
springrabbitmqspring-amqpspring-rabbit

Tomcat Server Hanging During Startup When Using Spring Rabbit


I am using spring rabbit 1.5.1 in one of my projects & I have some custom code which creates listener container objects on the fly during the startup (not in the configuration, but programmatically via a bean).
But the server never seem to comeup & hangs for ever.
When I took the thread dump, this is what I found out so far.

***"SimpleAsyncTaskExecutor-1" #38 prio=5 os_prio=31 tid=0x00007f84bf220000 nid=0x8503 waiting for monitor entry [0x000000012a583000]
java.lang.Thread.State: BLOCKED (on object monitor)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:187)
- waiting to lock <0x00000007713d46b0> (a java.util.concurrent.ConcurrentHashMap)
at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:488)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:447)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:423)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:530)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:523)
at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1153)
at org.springframework.amqp.rabbit.core.RabbitAdmin.initialize(RabbitAdmin.java:384)
at org.springframework.amqp.rabbit.core.RabbitAdmin$11.onCreate(RabbitAdmin.java:351)
at org.springframework.amqp.rabbit.connection.CompositeConnectionListener.onCreate(CompositeConnectionListener.java:32)
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:502)
- locked <0x0000000774662870> (a java.lang.Object)
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils$1.createConnection(ConnectionFactoryUtils.java:80)
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.doGetTransactionalResourceHolder(ConnectionFactoryUtils.java:130)
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.getTransactionalResourceHolder(ConnectionFactoryUtils.java:67)
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:456)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1158)
at java.lang.Thread.run(Thread.java:745)***

along with one more below:

***"SimpleAsyncTaskExecutor-1" #41 prio=5 os_prio=31 tid=0x00007f84bb162800 nid=0x8b03 waiting for monitor entry [0x0000000126e73000]
java.lang.Thread.State: BLOCKED (on object monitor)
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:498)
- waiting to lock <0x0000000774662870> (a java.lang.Object)
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils$1.createConnection(ConnectionFactoryUtils.java:80)
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.doGetTransactionalResourceHolder(ConnectionFactoryUtils.java:130)
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.getTransactionalResourceHolder(ConnectionFactoryUtils.java:67)
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:456)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1158)
at java.lang.Thread.run(Thread.java:745)***

I am not sure how to get over this problem. Looking forward for some inputs/directions to solve this.


Solution

  • You need to show your code; you say you're creating the containers programmatically, (outside of Spring), yet you are interacting with the application context via the RabbitAdmin.

    You can't have it both ways; either use a context, or don't.

    You need to find which thread owns this lock

    waiting to lock <0x00000007713d46b0>
    

    and you might be able to figure out a work-around.

    One possibility would be to use a separate connection factory (created outside of a Spring application context) so the rabbit admin is not invoked to declare the queues etc.

    Another way might be to disable RabbitAdmin auto declaration by setting autoStartup to false.

    But, the first step is to find out who owns that lock.