Thanks Grzesiek for your update.
We will review the issue using your information and update it.
Regards
JB
Grzegorz Kokosiński wrote:
Hi.
Issue:
http://issues.apache.org/activemq/browse/SM-343?page=com.atlassian.jira.plugin.ext.subversion%3Asubversion-commits-tabpanel
Lastly I encountered on problem described in this issue. I have looked
inside the code and I found what had happened. I hope that it will help
someone of You to resolve this isssue.
So this how it looks.
First thread is trying to suspend flow and invokes suspend method on
AbstractFlow, so it takes monitor of this object because this method is
synchronized. But it does not lock writeLock for this moment.
The second thread is trying to execute send method. So it locks
readLock, then invokes doSend method of class SedaFlow, then inside this
method it invokes enqueuePacket method and tries to create queue by
method createQueue. But this method is synchronized, and monitor of this
object is taken by first thread, so it cannot execute it till the first
thread will leave suspend method. But first thread is trying to lock
writeLock, but it cannot do that, because second thread lock readLock...
and we have deadlock.
I have copied some of code, maybe it will be helpful.
AbstractFlow.java (servicemix-3.3.1)
116 public void send(MessageExchange me) throws JBIException {
117 if (log.isDebugEnabled()) {
118 log.debug("Called Flow send");
119 }
120 // do send
121 try {
122 lock.readLock().lock();
123 doSend((MessageExchangeImpl) me);
124 } finally {
125 lock.readLock().unlock();
126 }
127 }
AbstractFlow.java (servicemix-3.3.1)
132 public synchronized void suspend() {
133 if (log.isDebugEnabled()) {
134 log.debug("Called Flow suspend");
135 }
136 lock.writeLock().lock();
137 suspendThread = Thread.currentThread();
138 }
SedaFlow.java (servicemix-3.3.1)
176 protected void enqueuePacket(MessageExchangeImpl me) throws
JBIException {
177 ComponentNameSpace cns = me.getDestinationId();
178 SedaQueue queue = queueMap.get(cns);
179 if (queue == null) {
180 queue = createQueue(cns);
181 }
182 try {
183 queue.enqueue(me);
184 } catch (InterruptedException e) {
185 throw new MessagingException(queue + " Failed to enqueue
exchange: " + me, e);
186 }
187 }
188
189 protected synchronized SedaQueue createQueue(ComponentNameSpace
cns) throws JBIException {
Grzesiek