JZOS clean way to implement a handleStop() callback

General discussion on the JZOS batch launcher and toolkit
Post Reply
Posts: 18
Joined: Wed Jan 18, 2006 5:53 am

JZOS clean way to implement a handleStop() callback

Post by bilbozos » Tue Aug 16, 2011 4:07 pm


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
// Close connections


// Implementation of handleStop()
public boolean handleStop() {
      this.running = false;
      return true;
If class is blocked in line (1), how could I manage to force the main loop to exit cleanly? I hace also read something about defining a shutdownHook so that some code is run before JVM ends. I'm not sure whether this is a good path to follow.

Any hint or suggestion would be highly appreciated.
Thanks in advance.

Site Admin
Posts: 1894
Joined: Thu Jul 29, 2004 12:12 pm

Re: JZOS clean way to implement a handleStop() callback

Post by dovetail » Fri Aug 19, 2011 4:45 pm

You should be able to execute code in the handleStop() method, before returning.

Posts: 3
Joined: Tue Jul 01, 2014 10:59 am

Re: JZOS clean way to implement a handleStop() callback

Post by akadian » Fri May 29, 2015 3:59 am


Could you please provide your Java code to connect/Read/Put etc. on MQ using JzOS? It will be really helpful if you can provide a working example of the same.


Post Reply