keenan
09-11-2008, 08:22 PM
If an application makes use of both synchronous and asynchronous messaging, for example by calling NmsTemplate.Receive() methods and also having one or more listener containers, then it is not possible to use the same CachingConnectionFactory instance for both. Is the a correct statement?
The reason I make this claim is based on errors I see in our logs. As I mentioned in a different forum post, the ActiveMQ Connection class does not lock on SyncRoot in any of the methods that enumerate the sessions collection.
In a multi-threaded service if one synchronous consumer thread is in the CreateSession() method and hits the sessions.Add() line while another thread is in the Start() method in the loop that is enumeratins sessions, an error occurs. In fact, the error is swallowed by AbstractListenerContainer:
Ignoring Connection start exception - assuming already started
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.ArrayList.ArrayListEnumeratorSi mple.MoveNext()
This was happening quite often in our case during service startup while the context was initializing objects.
The easy and straightforward solution was to create two CachingConnectionFactory instances in the configuration and use one for the asynchronous listeners and use the other for NmsTemplate.
Is there any downside or problems with that approach?
The reason I make this claim is based on errors I see in our logs. As I mentioned in a different forum post, the ActiveMQ Connection class does not lock on SyncRoot in any of the methods that enumerate the sessions collection.
In a multi-threaded service if one synchronous consumer thread is in the CreateSession() method and hits the sessions.Add() line while another thread is in the Start() method in the loop that is enumeratins sessions, an error occurs. In fact, the error is swallowed by AbstractListenerContainer:
Ignoring Connection start exception - assuming already started
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.ArrayList.ArrayListEnumeratorSi mple.MoveNext()
This was happening quite often in our case during service startup while the context was initializing objects.
The easy and straightforward solution was to create two CachingConnectionFactory instances in the configuration and use one for the asynchronous listeners and use the other for NmsTemplate.
Is there any downside or problems with that approach?