Parallel stream doesn#39;t set Thread.contextClassLoader after tomcat upgrade(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));
这篇关于Tomcat升级后并行流不设置Thread.contextClassLoader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Tomcat升级后并行流不设置Thread.contextClassLoader
基础教程推荐
- Java:带有char数组的println给出乱码 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 降序排序:Java Map 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01