++++++++++++++++++++++++++++++++++++++++++++++

MSDN talking about lock(this)

http://msdn.microsoft.com/en-us/library/c5kehkcz(VS.80).aspx
lock (this) is a problem if the instance can be accessed publicly.

I see lock(this) used heavily in MessageConsumer class....
the consumer will be accessible to the main app as well.

DEADLOCK SCENARIO:

the deadlock occurs on close method of IMessageConsumer.

Here is the scenario...
Lets say we have the class below. The producer is calling the
MessgeConsumers callback method.
In this case its onMessage() method. Now lets assume there are 30K messages
to be received in the call back. When we are on the 10th message and the
user closes the trace Window the CloseWindow() method is called and the
application stalls at the message consumers close method.
Hope I am clear enough.

Class TraceWindow
{
private IMessageConsumer consumerTrace = null;
TraceWindow(Apache.NMS.IMessageConsumer iMessageConsumer)
{
            this.consumerTrace = iMessageConsumer;
            if (consumerTrace != null)
            {
                this.consumerTrace.Listener += new
MessageListener(OnMessage);
            }
}

 public void OnMessage(Apache.NMS.IMessage bMsg)
{
        //inserts in WPF ObservableCollection
            handleMessageDelegate Updater = new
handleMessageDelegate(handleMessage);
           
this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Input,
                     Updater, obj);       
}

public void handleMessage(Object item)
        {                        
            lock (collectionTrace)
            {  
                {                    
                    collectionTrace.Add(item);
                   
LogManager.GetLogger("AlgoSystemCommunicatorLogger").Info(item);    
                }
            }
        }       


public void CloseWindow()
{
   consumerTrace.Close();   //////////////////////SYSTEM STALLS ON THIS CALL
}

}//end of class



+++++++++++++++++++++++++++++++++++++++++++++++


Timothy Bish wrote:
> 
> On Wed, 2009-01-21 at 10:26 -0800, sbs1982 wrote:
>> If one thread in my app is trying to create a temporary topic and I
>> already
>> have a few consumers(listening on other temp topics & processesing
>> incoming
>> messages on their respective call back methods i.e listeners) open. Now
>> trying to call the close method of one of these consumers causes my app
>> to
>> go into deadlock. 
> 
> Can you create a test case that might reproduce the problem?  If you run
> in the debugger can you pinpoint where the deadlock is occurring?  
> 
>> is there some know issue of close method of consumers locking? 
>> 
>> I looked at the code in the MessageConsumer..the first statement is
>> lock(this). 
>> Some articles are out there saying that locking on this is unsafe? 
> 
> Can you provide references, I'd like to read up on this (no pun
> intended).
> 
> You may want to create a Jira issue to cover this problem.
> 
> Regards
> Tim.
> 
> 
> -- 
> Tim Bish
> http://fusesource.com
> http://timbish.blogspot.com/
> 
> 
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/is-ISession-thread-safe--tp21589189p21590482.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Reply via email to