首页 > 解决方案 > IBM Liberty Profile 中的多线程执行器服务

问题描述

我正在使用 ExecutorService 进行一些测试,以在 Liberty 中执行多线程。从我的测试看来,启动可以使用 JCICS APi 的线程(例如创建新的 TSQ)的唯一方法是使用静态方法

CICSExecutorService.runAsCics(task1)

如果我以另一种方式启动线程,例如:

// in this way, the OSGi should create an instance of CICSExecutorService automatically
ExecutorService cicsExecutor = Executors.newFixedThreadPool(1); 
cicsExecutor .submit(task1);

线程无法使用 JCICS APi;特别是我得到这个错误:

java.util.concurrent.ExecutionException: com.ibm.cics.server.CicsRuntimeException: DTCTSQ_READITEM: 
                                            No JCICS context is associated with the current thread. 

那是对的吗?谢谢。

标签: javaexecutorservicewebsphere-libertycics

解决方案


没错,将您的可运行/可调用(task1)提交给您自己新创建的 Executor 不会在支持 CICS 的线程(也不是 Liberty 托管线程)上运行。

如果您使用的是 CICS TS v5.3 或更高版本,那么有许多方法可用,您可以使用 CICSExecutorService.runAsCICS(),该方法经过优化以使用 Liberty 的托管执行器。您可以直接从 OSGi 服务中查找 Liberty 的 Managed Executor,或者您可以@Inject Executor 的一个实例并将 Liberty concurrent-1.0 功能添加到您的 server.xml(有关详细信息,请参阅后面的答案)。

如果您使用的是 v5.3 之前的版本,则 CICSExecutorService.runAsCICS() 方法可用,但它不会与 Liberty 的托管执行器集成,因此您将仅限于 JCICS 操作,而 Java EE (Liberty) 功能将不会在该可运行/可调用任务中可用。


推荐阅读