MyServerSession.java

 

This class implements the javax.jms.ServerSession interface. It associates a thread with a JMS session. Instances of this class are pooled by a ServerSessionPool (see MyServerSessionPool.java). As a ServerSession, it must implement the following two methods:

MyServerSession also implements the Runnable interface. Therefore, the creation of the ServerSession's thread can be based on this class, and does not need a separate class.

The class uses a wait()-notify() mechanism that is based on the values of two boolean flags, ready and quit. This mechanism means that the ServerSession creates and starts its associated thread during its construction. However, it does not automatically execute the body of the run() method. The body of the run() method is executed only when the ready flag is set to true by the start() method. The ASF calls the start() method when it is necessary to deliver messages to the associated JMS session.

For delivery, the run() method of the JMS session is called. The WebSphere MQ JMS ASF will have already loaded the run() method with messages.

After delivery completes, the ready flag is reset to false, and the owning ServerSessionPool is notified that delivery is complete. The ServerSession then remains in a wait state until either the start() method is called again, or the close() method is invoked and ends this ServerSession's thread.


uj25650_