[rabbitmq-discuss] JAVA client / non daemon threads / shutdown hook
prokop.bart at gmail.com
Fri May 18 15:47:25 BST 2012
I'm using JAVA client for RabbitMQ (com.rabbitmq:amqp-client:2.8.1) to
write a "jar component" capable of sending messages for some legacy system.
The idea is to wrap all code that maintain the connection inside my
component. This way, the client software deals only with very simple
methods like "post" and is not aware of any connection handling. The
connect/reconnect code is written and hidden from the legacy system.
The problem I have faced is that Java client creates "behind the scene"
some threads to manage connection - like:
lines 299-301 of AMQConnection class.
// start the main loop going
new MainLoop("AMQP Connection " + getHostAddress() + ":" +
// after this point clear-up of MainLoop is triggered by closing
Unfortunatelly, those threads aren't "daemon" threads. So, when main
application ends and appropriate connection closing not occurs, the VM
won't terminate. My approach was to add some shutdown hook to close
RabbitMQ connections if it is live inside my "jar component". But, due to
those non-daemon threads, VM is not going ever to be terminated and
shutdown hooks fired.
It is a question to RabbitMQ driver developers, if the internal threads
could be fired as daemon threads, could it be done in future releases?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rabbitmq-discuss