|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
MQEnvironment Thread Safety?? |
« View previous topic :: View next topic » |
Author |
Message
|
jh72i |
Posted: Tue Oct 11, 2005 3:19 am Post subject: MQEnvironment Thread Safety?? |
|
|
Newbie
Joined: 05 Sep 2005 Posts: 5
|
Hi,
My question today is whether or not MQEnvironment is thread safe? (BTW I find it very hard to find specific information about MQ for .NET out there so any pointer would be great)
I have a scenario where I am 'subscribing' to two different queues and, basically, listening for messages all day . Up to now both queues were on the same host so I never encountered the problem I'm going to attempt to explain below.
Very simply what I have is...
. a class that wraps the functionality of MQ I need
. a windows service that simply starts up and creates 2 instances of this class
. the first instance creates a thread which connects and listens for messages on a queue
. the second does same but on a different queue
. the second fails to connect with a MQRC_Q_MGR_NAME_ERROR
. however, if I remove the connection to the first queue the second connects fine!
Now, my Connect() method uses MQEnvironment to set the Host, Channel and Port before creating a new MQQueueManager.
I have put in some debug code into the failure situation and have found that those three properties actually retain their values from the first call to connect which happens on a different thread.
So, for example this (pseudo) code does some funny stuff when it is run in a threaded situation
Code: |
Connect()
{
MQEnvironment.Hostname = _hostName;
MQEnvironment.Channel = _channelName;
MQEnvironment.Port = _port;
// I check these values now and they are correct even for the second connect
MQEnvironment.Channel, MQEnvironment.Hostname, MQEnvironment.Port
try
{
_manager = new MQQueueManager(_managerName);
}
catch (MQException exMQ)
{
// NOW if I check these they have lost their values from *** above
// and reverted to the first call to connect
MQEnvironment.Channel, MQEnvironment.Hostname, MQEnvironment.Port
} |
So, to me it seems that those MQEnvironment properties get their values overwritten between calls on two separate threads - i.e. they do not seem to be thread safe!? If I remove threading completely from this equation each queue connect works as expected.
To maybe explain a little better how I'm using threading: a client application (in this instance a Windows Service) creates an instance of WebSphereQueueManager for each configured queue. As part of the creation process it calls .Subscribe which spawns a new thread to Connect, Listen & Process messages until an Unsubscribe event occurs. So, in effect the two threads can be at different lines of code within the WebSphereQueueManager class at the same time BUT these are unique instance so no threading problems should occur. Unless the MQEnvironment is somehow being shared between both instances and is not implementing locking, etc.
Long rant sorry but what I really need to know is: IS MQEnvironment Thread Safe?
Thanks
John |
|
Back to top |
|
 |
PeterPotkay |
Posted: Wed Oct 12, 2005 5:18 pm Post subject: Re: MQEnvironment Thread Safety?? |
|
|
 Poobah
Joined: 15 May 2001 Posts: 7722
|
jh72i wrote: |
(BTW I find it very hard to find specific information about MQ for .NET out there so any pointer would be great)
|
If you install MQ on a windows machine, the .NET pdf is installed as well, plus sample programs if you chose that option at install time.
If you click on the manuals button on the top of this screen, you will find the same .NET manual.
And on IBM's site, search for a "RedBook" about .NET and MQ. Big and fat with lots of good info. _________________ Peter Potkay
Keep Calm and MQ On |
|
Back to top |
|
 |
wschutz |
Posted: Wed Oct 12, 2005 5:59 pm Post subject: |
|
|
 Jedi Knight
Joined: 02 Jun 2005 Posts: 3316 Location: IBM (retired)
|
Quote: |
If you click on the manuals button on the top of this screen, you will find the same .NET manual. |
Me thinks that link is broken  _________________ -wayne |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Oct 12, 2005 6:11 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
wschutz wrote: |
Me thinks that link is broken  |
It's been broken for Firefox for a while. Brandon never updated the javascript that turns the plain button into a menu to work for firefox - and he never updated what the plain button points to when he *added* the javascript.
So the plain button points to what was the main library page for 5.2 or so, and was not ever updated to reflect the change to the WebSphere brand.
I would guess (because I don't want to both to read the html source of this page) that the javascript menu points to the 5.3 library main page... which moved when v6 came out.... _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|