问题描述
在tomcat从8.5.6升级到8.5.28之后,并行流停止为contexts提供contextClassLoader:
After tomcat upgrade from 8.5.6 to 8.5.28 parallel stream stopped supplying Threads with contextClassLoader:
因为它 Warmer :: run
无法在其中加载类。
Because of it Warmer::run
can't load classes in it.
warmers.parallelStream().forEach(Warmer::run);
你有什么想法Tomcat为新线程提供contextClassLoaders的内容吗?
Do you have any ideas what Tomcat was supplying for contextClassLoaders for new Threads?
ParallelStream在最新的Tomcat中使用ForkJoinPool。
ParallelStream uses ForkJoinPool in newest Tomcat.
推荐答案
常见的ForkJoin池是有问题的,可能导致内存泄漏以及能够从其他上下文/应用程序加载类和资源的应用程序(如果您的tomcat是多租户,则可能发生安全漏洞)。请参阅此。
Common ForkJoin pool is problematic and could be responsible for memory leaks and for applications being able to load classes and resources from other contexts/applications (potential security leak if your tomcat is multi tenant). See this Tomcat Bugzilla Report.
在中,他们有通过引入
In Tomcat 8.5.11 they had applied fix to the above issues by introducing SafeForkJoinWorkerThreadFactory.java
为了您的代码为了工作,您可以执行以下操作,这将为 Stream.parallel()$ c提供明确的 ForkJoin 及其工作线程工厂 $ c>执行。
In order for your code to work, you can do the following, which will supply explicit ForkJoin and its worker thread factory to the Stream.parallel()
execution.
ForkJoinPool forkJoinPool = new ForkJoinPool(NO_OF_WORKERS);
forkJoinPool.execute(() -> warmers.parallelStream().forEach(Warmer::run));
这篇关于并行流在tomcat升级后不设置Thread.contextClassLoader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!