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
基础教程推荐
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 存储 20 位数字的数据类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
