Threads

In a JVM server environment, an application that is running in an OSGi framework can use an ExecutorService to create threads that run on CICS® tasks asynchronously.

CICS provides an implementation of the Java™ ExecutorService interface. This implementation creates threads that can use the JCICS API to access CICS services. The JVM server registers the CICS ExecutorService as an OSGi service on startup. Use this service instead of the Java Thread class to create tasks that can use JCICS.

The ExecutorService that is provided by CICS is registered as high priority in the OSGi framework, so that it can be used by applications to create threads. Typically, an application uses the highest priority ExecutorService, unless it filters services to use a specific implementation.

If you want to create threads in your application, the preferred method is to use a generic ExecutorService from the OSGi registry. The OSGi registry automatically uses the CICS ExecutorService to create CICS threads when the application is running in a JVM server. This approach means that the application is decoupled from the implementation, so you do not have to use the JCICS API method to create threads.

However, if you are writing an application that is specific to CICS, you can choose to use a CICSExecutorService class in the JCICS API to request new threads.

CICSExecutorService

This class implements the java.util.concurrent.ExecutorService interface. The CICSExecutorService class provides a static method called runAsCICS() which you can use to submit a Runnable Java object for running on a new JCICS enabled thread. The runAsCICS() method is a utility method which performs the OSGi registry look-up to obtain an instance of a CICSExecutorService for the application.

Because this class is registered as an implementation of the Java ExecutorService interface, any application that requests an ExecutorService is only given the CICSExecutorService when it runs in a JVM server.

CICSExecutorService.runAsCICS(Runnable runnable)

Restrictions

You must use the execute() method to create threads that can use JCICS. If you use the submit() method, the application gets a Java thread that cannot run JCICS.

For applications that are not running in an OSGi framework, for example an Axis2 Java program, you can access JCICS only on the initial application thread as the ExecutorService is not available. Additionally, you must ensure that all threads other than the initial thread finish before you take any of the following actions: