Notes when connecting ibm mq Java clients to multiple threads

Source: Internet
Author: User

We often see the following ibm mq client code written by someone:

Mqenvironment. Port = 1414;
Mqenvironment. hostname = "147.151.240.48 ";
Mqenvironment. Channel = "system. Def. svrconn ";
Mqenvironment. properties. Put (MQC. transport_property, MQC. transport_mqseries );

// 1 Environment Settings

Qmgr = new mqqueuemanager ("mq1 ");

This type of code runs in a multi-threaded environment at risk: for example, the above Code runs to "// 1 Environment Settings", and another thread uses similar code

Environment Settings, assuming the code is as follows:

Mqenvironment. Port = 1415;
Mqenvironment. hostname = "......";
Mqenvironment. Channel = ".....";
Mqenvironment. properties. Put (MQC. transport_property,
MQC. transport_mqseries );

This thread changes mqenvironment. Port to 1415...

The first thread constructs the queue manager: qmgr = new mqqueuemanager ("mq1"). At this time, the port passed to the "mq1" structure becomes

1415, the queue manager will not be connected.

 

The correct method should be to input the corresponding settings into the constructor every time the queue manager is constructed:

Hashtable prop = new hashtable ();
Prop. Put (maid, 1414 );
Prop. Put (MQC. host_name_property, "147.151.240.48 ");
Prop. Put (MQC. channel_property, "system. Def. svrconn ");
Prop. Put (MQC. transport_property, MQC. transport_mqseries );

 

Qmgr = new mqqueuemanager ("mq1", Prop );

 

In this way, there will be no problem between threads.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.