Vous pouvez créer une unité d'exécution qui démarre une tâche dans CICS en utilisant le CICSExecutorService. Si vous utilisez ce service pour créer une unité d'exécution, une tâche CICS est créée et elle peut utiliser l'API JCICS pour accéder aux services CICS.
Vous avez deux possibilités pour créer une unité d'exécution qui démarre une tâche CICS. Si vous souhaitez que votre code soit transférable, vous pouvez utiliser ExecutorService dans l'infrastructure OSGi. Lorsque l'application est exécutée dans le serveur JVM, l'infrastructure OSGi utilise la mise en oeuvre CICS pour démarrer une tâche CICS lorsqu'une unité d'exécution est créée. Si vous écrivez une application spécifiquement pour CICS, vous pouvez utiliser la classe CICSExecutorService directement en utilisant JCICS.
package com.ibm.cics.executor.test;
import com.ibm.cics.server.CICSExecutorService;
import com.ibm.cics.server.TSQ;
import com.ibm.cics.server.TSQType;
public class ExecutorTest
{
public static void main(String[] args)
{
// Inline the new Runnable class
class CICSJob implements Runnable
{
public void run()
{
// Create a temporary storage queue
TSQ test_tsq = new TSQ();
test_tsq.setType(TSQType.MAIN);
// Set the TSQ name
test_tsq.setName("TSQWRITE");
// Write to the temporary storage queue
// Use the CICS region local CCSID so it is readable
String test_string = "Hello from a non CICS Thread - "+ threadId;
try
{
test_tsq.writeItem(test_string.getBytes(System.getProperty("com.ibm.cics.jvmserver.local.ccsid")));
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
// Create and run the new CICSJob Runnable
Runnable task = new CICSJob();
CICSExecutorService.runAsCICS(task);
}
}