Multithreaded programs in Java
The Java runtime environment is inherently multithreaded. WebSphere® MQ classes for Java allows a queue manager object to be shared by multiple threads but ensures that all access to the target queue manager is synchronized.
Multithreaded programs are hard to avoid in Java . Consider a simple program that connects to a queue manager and opens a queue at startup. The program displays a single button on the screen. When a user clicks that button, the program fetches a message from the queue.
The Java runtime environment is inherently multithreaded. Therefore, your application initialization occurs in one thread, and the code that executes in response to the button press executes in a separate thread (the user interface thread).
With the C based WebSphere MQ MQI client, this would cause a problem, because there are limitations to the sharing of handles by multiple threads. WebSphere MQ classes for Java relaxes this constraint, allowing a queue manager object (and its associated queue, topic and process objects) to be shared by multiple threads.
com.ibm.mq.MQGetMessageOptions
must not be shared between threads which are requesting messages concurrently. Instances
of this class are updated with data during the corresponding MQGET
request, which can result in unexpected consequences when multiple
threads are operating concurrently on the same instance of the object.