[rabbitmq-discuss] How to tell Java Client running in a separate thread to stop consuming
steve at rabbitmq.com
Tue Oct 25 17:02:43 BST 2011
As I said, there is no 'safe' general mechanism for stopping
one Java Thread from another. The Interrupt mechanism in Java is
simply a convenience for *very simple cases*, or for debugging,
and cannot be regarded as safe on public interfaces.
* changes to the design of a service might involve invoking more
or fewer other threads (in which case you might be interrupting
the wrong one);
* services might be invoked which themselves quietly consume
* interrupts which fail to be trapped (due to timing considerations)
can contaminate the thread for the next time it is run;
* it is not possible to tell the difference between spurious interrupts
(part of the Java VM rules for wait(timeout)) and deliberate
It is much better to architect a solution. For example, in your case,
send a message to your client application which causes it to perform
an orderly shutdown (including, one would expect, cancelling consumers
and closing connections as we have discussed). The client might
already have such a message architected, or if not, design one.
In the next release of RabbitMQ the thread upon which consumers
perform their callbacks need neither be the client thread, nor the
connection thread, nor a thread dedicated to a particular channel.
In these circumstances, you are much better off calling a standard
interface like basicCancel().
Steve Powell (a happy bunny)
----------some definitions from the SPD----------
Rigatoni n. A prime-ministerial grin.
Nigella n. The next bottle-size up from a Nebuchadnezzar.
Homily adv. Rather like a frenchman.
On 21 Oct 2011, at 01:28, dusura wrote:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rabbitmq-discuss