Tomcat升级后并行流不设置Thread.contextClassLoader
在 tomcat 从 8.5.6 升级到 8.5.28 并行流后停止为线程提供 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.
推荐答案
Common ForkJoin pool 存在问题,可能导致内存泄漏以及应用程序能够从其他上下文加载类和资源/应用程序(如果您的 tomcat 是多租户,则可能存在安全漏洞).请参阅此 Tomcat Bugzilla 报告.
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.
在 Tomcat 8.5.11 他们已对上述问题进行了修复通过引入 SafeForkJoinWorkerThreadFactory.java
In Tomcat 8.5.11 they had applied fix to the above issues by introducing SafeForkJoinWorkerThreadFactory.java
为了让您的代码正常工作,您可以执行以下操作,这会将显式 ForkJoin 及其 worker thread factory 提供给 Stream.parallel()
执行.
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));
相关文章