activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aaron Digulla <digu...@hepe.com>
Subject Reliably starting and stopping of a producer/consumer
Date Wed, 10 Oct 2007 13:12:15 GMT

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.


Mime
View raw message