// Define a package name for the program
package unit_test;
// Import the JCICS package
import com.ibm.cics.server.*;
// Declare a class for a CICS application
public class JCICSTSQ {
// The main method is called when the application runs
public static void main(CommAreaHolder cah) {
try {
// Create and name a Temporary Storage queue object
TSQ tsq = new TSQ();
tsq.setName("JCICSTSQ");
// Delete the queue if it exists
try {
tsq.delete();
} catch(InvalidQueueIdException e) {
// Absorb QIDERR
System.out.println("QIDERR ignored!");
}
// Write an item to the queue
String transaction = Task.getTask().getTransactionName();
String message = "Transaction name is - " + transaction;
tsq.writeItem(message.getBytes());
} catch(Throwable t) {
System.out.println("Unexpected Throwable: " + t.toString());
}
// Return from the application
return;
}
}
When Java applications are run in CICS, the public static void main() method is called through the use of another Java program called the Java wrapper. The use of the wrapper allows CICS to initialize the environment for Java applications and, more importantly, to clean up any processes that are used during the life of the application. Killing the JVM, even with a clean return code of 0, does not allow this cleanup process to run, and may lead to data inconsistency. Also, a System.exit() call makes the continuous JVM mode unusable, because it terminates the JVM instance. The recommended approach is to allow the program to run to the end of the public static void main() method and the JVM to terminate cleanly.