gpt4 book ai didi

java - 传播 Java EE 上下文 Websphere

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:19:37 25 4
gpt4 key购买 nike

我正在开发在 Websphere 8.5 上运行的基于 Jersey 的 JAX-RS2 应用程序。我正在使用异步功能来生成一个新线程。问题是新线程没有获得 jndi 查找所需的 Java EE 上下文。我得到的错误是:

A JNDI operation on a java:comp/env name cannot be completed because the current thread is not associated with a Java Enterprise Edition application component. This condition can occur when the JNDI client using the java:comp/env name does not occur on the thread of a server application request. Make sure that a Java EE application does not run JNDI operations on java:comp/env names within static code blocks or in threads created by that application. Such code does not necessarily run on the thread of a server application request and therefore is not supported by JNDI operations on java:comp/env names.

Java EE 7 中的 ManagedExecutorService 特性可以在 websphere 中配置。我无法使用它,因为 Websphere 8.5 仅支持 Java EE 6。我无法提前进行查找,因为其中包含需要 Java EE 上下文才能工作的第三方 jar。

我想将 Java EE 上下文传播到新生成的线程。请建议是否可行。

最佳答案

通过在 WebSphere Application Server 中创建工作管理器,可以将任务提交给具有 J2EE 上下文的新线程。对于 WAS 8 及更高版本,完整配置文件中可用的 WorkManager 现在也是一个 ExecutorService。其步骤是:

  1. 在 WAS 管理控制台上转到 Resources -->Asynchronous Beans--> Work manager 并使用 jndi 名称 wm/myWM 创建了一个新的 work manager。
  2. 在 java 代码中为工作管理器执行 jndi 查找。

    ExecutorService execService = (ExecutorService) initialContext.lookup("wm/myWM");

  3. 将任务提交给 Executor Service。

    execService.submit(new AsyncJob(inputData, asyncResponse));

在 Websphere Liberty 配置文件中,这可以配置为 managedExecutorService。 server.xml中需要添加以下内容

 <feature>concurrent-1.0</feature> 

<managedExecutorService jndiName="wm/myWM">
<contextService>
<jeeMetadataContext/>
<classloaderContext/>
<securityContext/>
</contextService>
</managedExecutorService>

更多详细信息位于此链接的 pdf 中:ManagedService WAS 8.5

关于java - 传播 Java EE 上下文 Websphere,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30387543/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com