您可以通过使用 CICSExecutorService 创建在 CICS 中启动任务的线程。如果您使用该服务创建线程,这将创建能使用 JCICS API访问 CICS 服务的 CICS 任务。
您有两个选项用于创建启动 CICS 任务的线程。如果要您的代码具有可移植性,那么您可使用 OSGi 框架中的 ExecutorService。当应用程序在 JVM 服务器中运行时,OSGi 框架将在创建线程后自动使用 CICS 实施来开始 CICS 任务。如果您正写入专用于 CICS 的应用程序,那么您可通过直接利用 JCICS 来使用 CICSExecutorService 类。
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);
}
}