Author |
Message
|
Washington Morais |
Posted: Thu Feb 09, 2012 9:30 am Post subject: Multiple Threads getting the same message |
|
|
Newbie
Joined: 09 Feb 2012 Posts: 7
|
Hi all.
I have an application that is using multiple threads to retrieve messages from MQ. Each Thread open a new connection to MQ. The problem is that differents Threads are reading the same message. Any help, please?
Code fragments:
Code: |
// Create a Task List
List<Task> procList = new List<Task>();
for (int i = 1; i <= intTotalTask; i++)
{
procList.Add(Task.Factory.StartNew(() => new MyObject().MyMethod()));
}
Task.WaitAll(procList.ToArray());
|
And the MQ Options
Code: |
MQGetMessageOptions mQGetMessageOptions = new MQGetMessageOptions();
mQGetMessageOptions.WaitInterval = 5000;
mQGetMessageOptions.Options = MQC.MQGMO_WAIT;
mQGetMessageOptions.Options |= MQC.MQPMO_SYNCPOINT;
|
Note: Then each [ MyObject().MyMethod() ] call, open a new connection to MQ
Tks in advance! |
|
Back to top |
|
 |
Vitor |
Posted: Thu Feb 09, 2012 9:40 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
WMQ version?
OS?
Platform (WAS, native, etc, etc)
How do you know it's the same message (same payload data, same message id in the MQMD, etc, etc)?
Do they all get the same message at the same time or does one thread pick it up, then another, then another?
Better information, better advice. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
bruce2359 |
Posted: Thu Feb 09, 2012 9:53 am Post subject: |
|
|
 Poobah
Joined: 05 Jan 2008 Posts: 9469 Location: US: west coast, almost. Otherwise, enroute.
|
Code: |
mQGetMessageOptions.Options |= MQC.MQPMO_SYNCPOINT; |
MQPMO_SYNCPOINT is an mqput option. _________________ I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live. |
|
Back to top |
|
 |
Washington Morais |
Posted: Thu Feb 09, 2012 10:13 am Post subject: |
|
|
Newbie
Joined: 09 Feb 2012 Posts: 7
|
bruce2359 wrote: |
Code: |
mQGetMessageOptions.Options |= MQC.MQPMO_SYNCPOINT; |
MQPMO_SYNCPOINT is an mqput option. |
True. I'll change it and see the result.
Tks |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Feb 09, 2012 10:18 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Also.
Open one connection for each thread that has to GET messages, and then one connection for all threads that need to PUT messages.
Do not open any more connections than that, and do not ever open one connection for each get. |
|
Back to top |
|
 |
bruce2359 |
Posted: Thu Feb 09, 2012 10:20 am Post subject: |
|
|
 Poobah
Joined: 05 Jan 2008 Posts: 9469 Location: US: west coast, almost. Otherwise, enroute.
|
Washington Morais wrote: |
bruce2359 wrote: |
Code: |
mQGetMessageOptions.Options |= MQC.MQPMO_SYNCPOINT; |
MQPMO_SYNCPOINT is an mqput option. |
True. I'll change it and see the result.
Tks |
This change should not give you different results, as both constants have the same numeric value. _________________ I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Feb 09, 2012 10:27 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
bruce2359 wrote: |
Washington Morais wrote: |
bruce2359 wrote: |
Code: |
mQGetMessageOptions.Options |= MQC.MQPMO_SYNCPOINT; |
MQPMO_SYNCPOINT is an mqput option. |
True. I'll change it and see the result.
Tks |
This change should not give you different results, as both constants have the same numeric value. |
The most likely cause here is that you're reusing the same MQMessage object and this is causing conflicts between the thread that did the last get and the thread that's trying to read the contents of the message.
i.e. make sure you at least clear the MQmessage object between gets and make sure that you are using a thread-local variable for the MQmessage object. |
|
Back to top |
|
 |
Washington Morais |
Posted: Fri Feb 10, 2012 4:16 am Post subject: |
|
|
Newbie
Joined: 09 Feb 2012 Posts: 7
|
Hi guys, tks for all answers. I guess i found the problem.
I was using Tasks for each message I wanted to read from MQ. I was thinking that Tasks and Threads are then same.
I changed my code to use explicitly Threads and all seams to work now.
p.s: i also changed MQPMO_SYNCPOINT to MQGMO_SYNCPOINT. |
|
Back to top |
|
 |
|