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 ECDSAwithSHA256 签名长度不一致 2022-01-01
- 将 double 转换为 Int,向下舍入 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- JPA惰性列表上的流 2022-01-01
- Maven:无效的目标版本:10 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
