java - 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.
那是对的吗?谢谢。
解决方案
没错,将您的可运行/可调用(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) 功能将不会在该可运行/可调用任务中可用。
推荐阅读
- git - 如何使用一个帐户克隆 git repo,然后使用第二个帐户推送
- redis - REDIS AOF 文件大小连续翻倍
- javascript - 如何在弹出窗口上制作带有下一个和上一个按钮导航的模态滑块
- php - 如何解密 Transak 的 webhook 有效载荷?
- java - 为什么在 Spring 批量测试中需要 JobLauncherTestUtils 和 JobRepositoryTestUtils?
- vue.js - 将 Vuex 数据从 API 传递到表
- java - 如何创建其父函数不抛出任何错误的抛出异常函数
- docker - docker中暴露端口的Vuejs应用程序不起作用
- javascript - 将 div 移动到其他隐藏的 div 中
- go - go中的select语句和选定的案例