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.