[rabbitmq-discuss] JAVA client / non daemon threads / shutdown hook
Bartłomiej Prokop
prokop.bart at gmail.com
Fri May 18 15:47:25 BST 2012
Hi,
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() + ":" +
getPort()).start();
// after this point clear-up of MainLoop is triggered by closing
the frameHandler.
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...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20120518/7d82c019/attachment.htm>
More information about the rabbitmq-discuss
mailing list