ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » mq with java,multithread application,can't putMsg

Post new topic  Reply to topic
 mq with java,multithread application,can't putMsg « View previous topic :: View next topic » 
Author Message
andy840920
PostPosted: Wed Aug 26, 2009 5:57 am    Post subject: mq with java,multithread application,can't putMsg Reply with quote

Apprentice

Joined: 29 Apr 2007
Posts: 44

my application like this:
Code:

while (true) {
    String msg = getQueue.getMsg();
    BusinessClass obj = new BusinessClass(msg); //extends Thread
    obj.start(); //start a thread to handle and the main thread continue getMsg
}

in obj.start() method need to call putQueue.putMsg() api to send a msg to other queue. but i found the method can't successful alway, and it block all the time.

i found something about it at http://publib.boulder.ibm.com/infocenter, that should Synchronized on the queue manager, or create one queue manager in every thread. somebody can help me?
Back to top
View user's profile Send private message
zpat
PostPosted: Wed Aug 26, 2009 6:40 am    Post subject: Reply with quote

Jedi Council

Joined: 19 May 2001
Posts: 5866
Location: UK

Unless you use handle sharing, each thread needs it's own queue manager and queue handle.

Since MQ is asynchronous anyway - there is no reason to do this, just issue the put in the same thread.
Back to top
View user's profile Send private message
andy840920
PostPosted: Wed Aug 26, 2009 6:48 am    Post subject: Reply with quote

Apprentice

Joined: 29 Apr 2007
Posts: 44

zpat wrote:
Unless you use handle sharing, each thread needs it's own queue manager and queue handle.

Since MQ is asynchronous anyway - there is no reason to do this, just issue the put in the same thread.
how to use handle sharing? my program like this:
Code:

public static QueueManager qmgr = new QueueManager ();
getQueue = qmgr.createGetQueue();
putQueue = qmgr.createPutQueue();
only one qmgr handler in my process. handle sharing how to write?
Back to top
View user's profile Send private message
andy840920
PostPosted: Wed Aug 26, 2009 6:52 am    Post subject: Reply with quote

Apprentice

Joined: 29 Apr 2007
Posts: 44

every thread need one queue handle?

so i must close queue after put or get msg, and open in the new thread to put or get? i think that is not efficient. so all thread use two queue handle to get or put msg in my program.
Back to top
View user's profile Send private message
zpat
PostPosted: Wed Aug 26, 2009 6:54 am    Post subject: Reply with quote

Jedi Council

Joined: 19 May 2001
Posts: 5866
Location: UK

No you don't have to close the queue, multiple threads can access the same queue at the same time.

Your design is simply wrong. MQ is async anyway - you don't need to create additional threads for this purpose.

Read the manual about handle sharing but you don't need to do this.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Wed Aug 26, 2009 7:05 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

You can't issue a PUT on a CONNECTION that is in a pending GET. You can not in general issue more than one MQ call on a single connection at the same time.

You can use the same QueueManager object for all of your puts. You need one QueueManager object for each separate GET you wish to issue *simultaneously*.

The loop posted will start the thread, and then immediately go back to the GET. If the separate thread tries to issue the PUT before the GET succeeds, the connection will block until the GET completes. If the GET is sitting in long wait, then PUT will block until the GET returns. Given this code, the various threads will be blocking in an apparently random manner, based on an internal dispatch order.
Back to top
View user's profile Send private message
andy840920
PostPosted: Wed Aug 26, 2009 7:11 am    Post subject: Reply with quote

Apprentice

Joined: 29 Apr 2007
Posts: 44

Quote:
No you don't have to close the queue, multiple threads can access the same queue at the same time.

Your design is simply wrong. MQ is async anyway - you don't need to create additional threads for this purpose.

Read the manual about handle sharing but you don't need to do this.

Code:

while (true) {
    String msg = getQueue.getMsg();
    BusinessClass obj = new BusinessClass(msg); //extends Thread
    obj.start(); //start a thread to handle and the main thread continue getMsg
}
why in obj.start() can't put a msg into another queue. how to design my program, i need is only when the main thread receive a msg and start a thread to handle, i won't block the main thread to recveive msg.
Back to top
View user's profile Send private message
andy840920
PostPosted: Wed Aug 26, 2009 7:22 am    Post subject: Reply with quote

Apprentice

Joined: 29 Apr 2007
Posts: 44

so if my program like this:
Code:

Qmgr putQmgr = new Qmgr();
Qmgr getQmgr = new Qmgr();
public static PutQueue putQueue = putQmgr.createPutQueue();
public static GetQueue getQueue = getQmgr.createGetQueue();

while (true) {
    String msg = getQueue.getMsg();
    BusinessClass obj = new BusinessClass(msg); //extends Thread
    obj.start(); //start a thread to handle and the main thread continue getMsg
}

class BusinessClass  extends Thread {
    void run() {
         putQueue.putMsg();
    }
}
it's ok? use two QMGR.
Back to top
View user's profile Send private message
andy840920
PostPosted: Wed Aug 26, 2009 8:32 am    Post subject: Reply with quote

Apprentice

Joined: 29 Apr 2007
Posts: 44

zpat wrote:
No you don't have to close the queue, multiple threads can access the same queue at the same time.

Your design is simply wrong. MQ is async anyway - you don't need to create additional threads for this purpose.

Read the manual about handle sharing but you don't need to do this.
async anyway? but my GET method is waiting until get a msg. and the PUT method can't return if it's not send successful.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Wed Aug 26, 2009 8:39 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

andy840920 wrote:
zpat wrote:
No you don't have to close the queue, multiple threads can access the same queue at the same time.

Your design is simply wrong. MQ is async anyway - you don't need to create additional threads for this purpose.

Read the manual about handle sharing but you don't need to do this.
async anyway? but my GET method is waiting until get a msg. and the PUT method can't return if it's not send successful.


I suspect that zpat's meaning was that you do not need to process each message in parallel, as you are not in any way blocking the sender of the messages you are processing.

Now, whether or not you are running in a request/reply scenario that has a very tight SLA is a separate question, and may indeed require that you processing multiple requests simultaneously.

Although if you are in that kind of a situation, you may want to highly consider porting your code to JMS and running inside an Application Server instead of trying to reinvent all of the scalability and connection pooling and management that comes with Message Driven Beans.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » mq with java,multithread application,can't putMsg
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.