Connection pooling in IBM MQ classes for Java
IBM MQ classes for Java allows spare connections to be pooled for reuse.
IBM MQ classes for Java provides additional support for applications that deal with multiple connections to IBM MQ queue managers. When a connection is no longer required, instead of destroying it, it can be pooled and later reused. This can provide a substantial performance enhancement for applications and middleware that connect serially to arbitrary queue managers.
IBM MQ provides a default connection pool. Applications can activate or deactivate this connection pool by registering and deregistering tokens through the MQEnvironment class. If the pool is active when IBM MQ classes for Java constructs an MQQueueManager object, it searches this default pool and reuses any suitable connection. When an MQQueueManager.disconnect() call occurs, the underlying connection is returned to the pool.
Alternatively, applications can construct an MQSimpleConnectionManager connection pool for a particular use. Then, the application can either specify that pool during construction of an MQQueueManager object, or pass that pool to MQEnvironment for use as the default connection pool.
To prevent connections from using too much resource, we can limit the total number of connections that an MQSimpleConnectionManager object can handle, and we can limit the size of the connection pool. Setting limits is useful if there are conflicting demands for connections within a JVM.
By default, the getMaxConnections() method returns the value zero, which means that there is no limit to the number of connections that the MQSimpleConnectionManager object can handle. We can set a limit by using the setMaxConnections() method. If you set a limit and the limit is reached, a request for a further connection might cause an MQException to be thrown, with a reason code of MQRC_MAX_CONNS_LIMIT_REACHED.
- Control the default connection pool in IBM MQ classes for Java
This example shows how to use the default connection pool. - The default connection pool and multiple components in IBM MQ classes for Java
This example shows how to add or remove MQPoolTokens from a static set of registered MQPoolToken objects. - Supplying a different connection pool in IBM MQ classes for Java
This example shows how to use the class com.ibm.mq.MQSimpleConnectionManager to supply a different connection pool.
Parent topic: Writing IBM MQ classes for Java applications