将 JCICS 与异步 API 配合使用

CICS 异步 API 的 JCICS 变体作为一组类以及 java.util.concurrent.Future 接口的实现提供。

以下类中提供了所有 EXEC CICS 异步 API 命令的 Java 变体:
  • AsyncService
  • AsyncServiceImpl
  • ChildResponse

要从 Java 程序启动子事务,必须先获取 AsyncService 的新实例,然后再启动子事务。 AsyncServiceImpl 类中未持久存储任何状态,因此未来对象的作用域不会限定为其 AsyncService实例。

AsyncService asService = new AsyncServiceImpl();
Future<ChildResponse> child = asService.runTransactionId("ABCD");

虽然不支持与取消子任务相关的方法,但生成的 Future 对象可以正常使用。

runTransactionId() 是非分块的,但 get() 旨在符合 Future 接口并将分块。

与 CICS API 实现不同, get()getAny() 调用始终尝试从子代检索通道,并且该通道的所有权将立即转移到父任务。

要接收来自子任务的信息,可以使用 get() 方法。 例如:
ChildResponse response = child.get();
ChildResponse 提供了以下方法:
  • getAbendCode()
  • getChannel()
  • getCompletionStatus()
ChildResponse 还包含枚举 CompletionStatus,用于枚举子任务返回的可能 CVDA 值。
表 1.
Java 类 方法 等效的 CICS API
AsyncService
runTransactionId(String transactionId)
runTransactionId(String transactionId, Channel channel)
RUN TRANSID
RUN TRANSID CHANNEL
AsyncService
freeChild(ChildResponse child)
freeChild(Future<ChildResponse> child)
FREE CHILD
FREE CHILD
ChildResponse
ChildResponse.getAny()
ChildResponse.getAny(BlockingAction blockingAction)
ChildResponse getAny(long timeout, TimeUnit timeUnit)
FETCH ANY CHANNEL COMPSTATUS ABCODE
FETCH ANY NOSUSPEND CHANNEL COMPSTATUS ABCODE
FETCH ANY TIMEOUT CHANNEL COMPSTATUS ABCODE
Future<ChildResponse>
get()
get(long timeout, TimeUnit timeUnit)
FETCH CHILD CHANNEL COMPSTATUS ABCODE
FETCH CHILD CHANNEL COMPSTATUS ABCODE TIMEOUT
Future<ChildResponse> isDone() FETCH CHILD NOSUSPEND COMPSTATUS

示例

final String childTransaction = "ABCD";
AsyncService asService = new AsyncServiceImpl();

Future<ChildResponse> child = asService.runTransactionId(childTransaction);

// Logic here to be processed while the child runs asynchronously 

ChildResponse response = child.get();
if (response.getCompletionStatus().equals(CompletionStatus.NORMAL)) {
  System.out.println("Child task completed normally");
}