Details
Description
I've found that rarely .NET process consumes ~90% CPU. I got the dump file and I found that the problem is in Dictionary<>.FindEntry method:
2de9e5a4 71711819 System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib],[System.__Canon, mscorlib]].FindEntry(System.__Canon) 2de9e5c4 716937f5 System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib],[System.__Canon, mscorlib]].ContainsKey(System.__Canon) 2de9e5c8 2aabdade Apache.NMS.ActiveMQ.Transport.TransportFactory.FindTransportFactory(System.String) 2de9e614 2aabd983 Apache.NMS.ActiveMQ.Transport.TransportFactory.NewInstance(System.String) 2de9e680 2aabd865 Apache.NMS.ActiveMQ.Transport.TransportFactory.CreateTransportFactory(System.Uri) 2de9e6f0 2aabd73b Apache.NMS.ActiveMQ.Transport.TransportFactory.CreateTransport(System.Uri) 2de9e70c 2aabd4f1 Apache.NMS.ActiveMQ.ConnectionFactory.CreateActiveMQConnection(System.String, System.String) 2de9e7a0 2aabd40a Apache.NMS.ActiveMQ.ConnectionFactory.CreateActiveMQConnection() 2de9e7b8 2aabd3a8 Apache.NMS.ActiveMQ.ConnectionFactory.CreateConnection()
I've searched for the solution and found a good article of Tess Ferrandez, explaining the situation - http://blogs.msdn.com/b/tess/archive/2009/12/21/high-cpu-in-net-app-using-a-static-generic-dictionary.aspx
It seems that all access to static Dictionary classes should be synchronized. I've added lock statements in the TransportFactory class to all appropriate places.