【问题标题】:Multithreading with Executor Service in IBM Liberty ProfileIBM Liberty Profile 中的多线程执行器服务
【发布时间】:2020-09-29 13:21:35
【问题描述】:

我正在使用 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. 

正确吗?谢谢。

【问题讨论】:

    标签: java executorservice websphere-liberty cics


    【解决方案1】:

    没错,将您的可运行/可调用(task1)提交给您自己新创建的执行程序不会在支持 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)该函数在该可运行/可调用任务中将不可用。

    【讨论】:

    • 用 CICS 发布特定信息更新了答案。
    【解决方案2】:

    诀窍是使用托管执行器(即ManagedExecutorService),这将允许您提交给它的工作在 Liberty 线程上运行,而不是使用非托管执行器(例如Executors.newFixedThreadPool(1))运行没有执行操作所需上下文的非托管线程。

    要获得ManagedExecutorService,您需要:

    1. 在您的 server.xml 中启用 concurrent-1.0 功能

    2. 通过执行以下操作注入或查找执行程序:

    @Inject
    ManagedExecutorService exec;
    
    // or
    
    // NOTE: This also requires the jndi-1.0 feature to be enabled
    ManagedExecutorService exec = InitialContext.doLookup("java:comp/ManagedExecutorService");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-06
      • 1970-01-01
      • 2021-06-21
      相关资源
      最近更新 更多