我们当前的遗留web应用程序在其中创建的线程不是由Application容器管理的。我必须用多线程的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:?]为了解决这个问题,我指的是Java EE中的并发实用程序。我为ManagedExecutorService和ManagedThreadFactory找到了类似的描述和示例。
在哪一种情况下哪一种更好,为什么?
发布于 2019-06-11 10:15:28
我用ManagedExecutorService解决了问题。
ExecutorService框架确实有更多处理线程的方法,而ManagedThreadFactory只能调用newThread()方法。
WebSphere问题可以通过使用ManagedExecutorService或ManagedThreadFactory来解决。这两种方法都有效。但是对于进一步的线程处理,ManagedExecutorService结果要好得多。
现在,这个解决方案导致相同的web应用程序在Tomcat上失败。JNDI命名异常。根据我的研究和开发,基于容器的并发在TomEE服务器中是支持的,而不是在Tomcat中,因此我们必须使用路由机制在代码之间切换,就像底层应用服务器那样。
https://stackoverflow.com/questions/56478742
复制相似问题