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 that is called runAsCICS() that you can use to send a Runnable or Callable Java object for execution 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.

For work that is spawned from a parent CICS thread, a new CICS task is created, and runs under the task user ID and transaction ID inherited from the parent. If the work is spawned from a non- CICS thread, the default CJSA transaction ID and default CICS user ID are used. If you want to guarantee the new task runs under a transaction ID of your choice, then your Runnable or Callable object should implement the CICSTransactionRunnable or CICSTransactionRunnable interface.

CICSExecutorService.runAsCICS(Runnable runnable)
CICSExecutorService.runAsCICS(Callable callable)

Restrictions

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:

  • link methods in class com.ibm.cics.server.Program
  • setNextTransaction(String) method in class com.ibm.cics.server.TerminalPrincipalFacility
  • setNextCOMMAREA(byte[]) method in class com.ibm.cics.server.TerminalPrincipalFacility
  • commit() method in class com.ibm.cics.server.Task
  • rollback() method in class com.ibm.cics.server.Task
  • Returning an AbendException exception from class com.ibm.cics.server