JavaEE中ManagedExecutorService和ManagedThreadFactory的区别

JavaEE中ManagedExecutorService和ManagedThreadFactory的区别,java,java.util.concurrent,Java,Java.util.concurrent,我们当前的传统web应用程序在其中创建线程,而不是由应用程序服务器容器管理。我必须用JavaEE多线程标准来修改它。 我的web应用在Tomcat上运行良好,但在Websphere上失败。 Websphere上的错误: ... ... Caused by: javax.naming.ConfigurationException: A JNDI operation on a "java:" name cannot be completed because the server

我们当前的传统web应用程序在其中创建线程,而不是由应用程序服务器容器管理。我必须用JavaEE多线程标准来修改它。
我的web应用在Tomcat上运行良好,但在Websphere上失败。
Websphere上的错误:

... ... Caused by: javax.naming.ConfigurationException: A JNDI operation on a "java:" name cannot be completed because the server runtime is not able to associate the operation's thread with any J2EE application component.  This condition can occur when the JNDI client using the "java:" name is not executed on the thread of a server application request.  Make sure that a J2EE application does not execute JNDI operations on "java:" names within static code blocks or in threads created by that J2EE 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:" names.
    at com.ibm.ws.naming.java.javaURLContextImpl.throwExceptionIfDefaultJavaNS(javaURLContextImpl.java:534) ~[com.ibm.ws.runtime.jar:?]
    at com.ibm.ws.naming.java.javaURLContextImpl.throwConfigurationExceptionWithDefaultJavaNS(javaURLContextImpl.java:564) ~[com.ibm.ws.runtime.jar:?]
    at com.ibm.ws.naming.java.javaURLContextImpl.lookupExt(javaURLContextImpl.java:485) ~[com.ibm.ws.runtime.jar:?]
    at com.ibm.ws.naming.java.javaURLContextRoot.lookupExt(javaURLContextRoot.java:485) ~[com.ibm.ws.runtime.jar:?]
为了解决这个问题,我指的是。我为和找到了类似的描述和示例

  • ManagedExecutorService:应用程序使用托管执行器服务异步执行提交的任务。任务是 在容器启动和管理的线程上执行。这个 容器的上下文被传播到执行 任务
  • ManagedThreadFactory:应用程序使用托管线程工厂创建托管线程。线程被启动并运行 由容器管理。容器的上下文被传播 到执行任务的线程。此对象也可用于 为特定用例提供自定义工厂(使用自定义线程) 例如,将特定/专有属性设置为 对象

在哪种情况下首选哪一种?为什么?

我已经通过使用ManagedExecutorService解决了这个问题

ExecutorService框架确实有更多的方法来处理线程,而ManagedThreadFactory只能调用newThread()方法

Websphere问题可以通过使用ManagedExecutorService或ManagedThreadFactory来解决。两者都有效。但对于进一步的线程处理,ManagedExecutorService的效果要好得多


现在,这个解决方案导致同一个web应用在Tomcat上失败。JNDI命名异常。根据我的研发,TomEE服务器支持基于容器的并发,而不是Tomcat,因此我们必须使用路由机制根据底层应用程序服务器在代码之间切换。

请发表评论为什么负面评级?所以,下次我可以提高。