Java runtime environment in CICS

CICS provides two runtime environments for running Java applications. Threadsafe applications can use a JVM server. Applications that are not threadsafe have to use pooled JVMs.

JVM servers

The JVM server is a runtime environment that can run tasks in a single JVM. This environment is preferred for running Java applications, because it reduces the virtual storage required for each Java task and allows CICS to run many tasks concurrently.

CICS tasks run in parallel as threads in the same JVM server process. Not only is the JVM shared by all CICS tasks, which might be running multiple applications concurrently, all static data and static classes are also shared. So to use a JVM server in CICS, a Java application must be threadsafe. Each thread runs under a T8 TCB and can access CICS services using the JCICS API.

You can write application code to start a new thread or call a library that starts a thread. However, these threads cannot access CICS services. Any attempt to access CICS services from an application-spawned thread results in a Java bm.exception. If you want to create threads in your application, ensure that they do not run beyond the lifetime of the CICS task that runs the application. When the system programmer disables the JVM server, CICS waits for all current threads running on T8 TCBs to finish in the JVM. However, any threads created by an application itself are terminated.

Because static data is shared by all threads running in the JVM server, you can create OSGi bundle activator classes to initialize static data and leave it in the right state when the JVM shuts down. A JVM server runs until the system programmer disables it, for example to add an application or fix a problem. By providing bundle activator classes, you can ensure that the state is correctly set for your applications. CICS has a timeout that specifies how long to wait for these classes to complete before continuing to start or stop the JVM server. You cannot use JCICS in startup and termination classes.

Do not use the System.exit() method in your applications. This method causes both the JVM server and CICS to shut down, affecting the state and availability of your applications.

Pooled JVMs

A pooled JVM can handle only one request for a Java application at a time, therefore many more JVMs are required in a CICS region. A pooled JVM is isolated, so a Java application does not have to be threadsafe. However, pooled JVMs are typically reused many times, potentially by different applications, so it is important to maintain transaction isolation and the state of data.

The main thread under which a JVM starts is called the Initial Process Thread (IPT). CICS ensures that the public static main method in any Java program runs under the IPT in a pooled JVM. If you want to create threads in your application, they must not attempt to access CICS services and must not run beyond the lifetime of the CICS task that starts the threads. If user threads continue to run after the IPT has returned control to CICS, these threads can damage isolation for the JVM when it is reused by another application, and can cause problems when CICS attempts to stop the JVM.