I have a Java batch class that connects to a local WebSphereMQ manager to process the messages that arrive. The program uses a blocking get method to read from the queue. So if no message is available, the program blocks until another message arrives or until a timeout. Each messages is processed and the result is update a DB2 table through JDBC.
As per the documentation, if I want this class to respond to MVS STOP commands, I must return true in handleStop(). While in the loop to process incoming MQ messages, there is a live MQ connection and a live JDBC connection. If I just return "true" from handleStop() method, JZOS will simply call System.exit() and that's it, but I'd like first to cleanly close the connections. The main loop is something like the following (pseudocode):
Code: Select all
// Connect to local WebSphere MQ
// Open a JDBC connection
boolean running = true;
MQMessage mqMsg = new MQMessage(...);
// Set blocking options when reading messages from local WebSphereMQ
while (running) {
(1) readMQ(mqMsg); // This is blocking if queue is empty
process(mqMsg);
}
// Close connections
...
// Implementation of handleStop()
public boolean handleStop() {
this.running = false;
return true;
}
Any hint or suggestion would be highly appreciated.
Thanks in advance.