Hi all!
I am implementing proper stopping (with ExecutorService.shutdownNow()) of a few
worker threads I have, that are consuming messages from the queue all the time,
and if there were no messages the threads wouldn't stop...
Thread.currentThread().isInterrupted() is always false. So after a little bit
of debugging I discovered that the problem lies in the fact that receive method
on MessageConsumer eats up the InterruptedException, which clears isInterrupted
flag.
Relevant code from BasicMessageConsumer.java:
public Message receive(long l) throws JMSException
{
...
catch (InterruptedException e)
{
_logger.warn("Interrupted acquire: " + e);
if (isClosed())
{
return null;
}
}
...
catch (InterruptedException e)
{
_logger.warn("Interrupted: " + e);
return null;
}
...
}
Even though the JMS standard does not specify how to handle such interrupt
(JMSException or returning null message), I'm sure the implementation shouldn't
just ignore it (which is basically what happens). When catching
InterruptedException, the interrupted flag should immediately be set back
(Thread.currentThread().interrupt()), so in the calling code we can still
detect such situation.
Any other point of view on this subject, or should I file a bug? :)
Btw: I got around this by not using timeout in receive() call, but I would be
more comfortable if the Consumer would wait for messages for a while, instead
of me looping like crazy in my code...
P.S.: Sorry if this should go to qpid-dev.
Regards,
Ales