You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Aaron Digulla <di...@hepe.com> on 2007/10/10 15:12:15 UTC

Reliably starting and stopping of a producer/consumer

Hello,

I'm trying to write code for a webapp which allows me to start and stop the
webapp no matter whether an ActiveMQ JMS server is running or not with
ActiveMQ 4.1.1. This means:

- Create the connection in a worker thread, so the webapp doesn't hang
during startup
- Interrupt the connection creation and kill the worker thread at shutdown
time if the server never came up

This works until the point when I have to shutdown the worker. In this
situation, we have two threads: Worker and Main. Everything happens in
ActiveMQConnection.

Worker hangs in ensureConnectionInfoSent() in syncSendPacket(), waiting for
the server to come up. Note that ensureConnectionInfoSent() is synchronized;
the connection is the lock object.

Main tries to stop the ActiveMQ client and calls "close()" on the
connection. close() calls checkClosed() which is also synchronized on the
connection object. This creates a deadlock since Worker won't release the
lock any time soon.

Is there a reason why checkClosed() is synchronized? It's only using a
AtomicBoolean and possibly throwing an exception. The next obstacle would be
checkClosedOrFailed() which is also synchronized. Again, I see no obvious
reason why it has to be.

Unfortunately, then I run into a wall. stop() also wants to synchronize on
the connection.

My next idea was to interrupt the Worker thread. This doesn't work but
creates an endless loop in FailoverTransport.oneway() (the inner while()
loop isn't terminated on InterruptedException).

So all in all, I see no way to create an ActiveMQConnection in a worker
thread and reliably stop the thread at shutdown of the webapp (*not* the
VM).

Has anyone solved this problem or do you just accept that your webapps hang
when the JMS server is not around?

Regards,

-- 
Aaron Digulla
-- 
View this message in context: http://www.nabble.com/Reliably-starting-and-stopping-of-a-producer-consumer-tf4600635s2354.html#a13135407
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Reliably starting and stopping of a producer/consumer

Posted by Aaron Digulla <di...@hepe.com>.
I have now opened an issue for this:
https://issues.apache.org/activemq/browse/AMQ-1470

Regards,

-- 
Aaron Digulla
-- 
View this message in context: http://www.nabble.com/Reliably-starting-and-stopping-of-a-producer-consumer-tf4600635s2354.html#a13292366
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Reliably starting and stopping of a producer/consumer

Posted by Aaron Digulla <di...@hepe.com>.
After some hacking in the sources, I've come up with a version of
FailoverTransport which doesn't hang in oneway() anymore. The "I want to
shutdown *now*" case is not properly handled in this code. Also, I need a
better way to get rid of the reconnectTask when I have to shut down.

One way I've found is the "disposed" flag but that's a bit of a hack. I
actually need a "shutdown now" flag but that flag must be checked at the
same places as "disposed" (and with the same truth value), so it would just
clutter the code (i.e. every check with disposed would have to be extended
with a check of shutdown-now). But this patch is beyond my capability to
understand the various dependencies.

What I need now are some pointers how to proceed. Should I open a bug report
or is that issue already solved in 5.0? Are you interested in my changes (if
only to see what I did)?

Regards,

-- 
Aaron Digulla
-- 
View this message in context: http://www.nabble.com/Reliably-starting-and-stopping-of-a-producer-consumer-tf4600635s2354.html#a13229979
Sent from the ActiveMQ - User mailing list archive at Nabble.com.