当前位置: 首页 > news >正文

StackOverflowError的JVM处理方式

背景:

事情来源于生产的一个异常日志
Caused by: java.lang.StackOverflowError: null at java.util.stream.Collectors.lambda$groupingBy$45(Collectors.java:908) at java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169) at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
发生该异常并定位到是某个规则的问题后,我们手动修复了规则,不过我们无法确定是否需要重启容器,所以引申出来了发生StackOverflowError是否需要重启容器恢复的讨论

JVM对StackOverflowError线程的处理

结论是JVM只会中断发生StackOverflowError的线程,对于其他未发生StackOverflowError的线程没有影响,验证代码如下:

package stackoverflow;/*** 验证JVM处理StackOverflowError的方式,只会中断异常线程,不影响主线程以及其他线程的执行*/
public class StackOverFlowTest {public static void main(String[] args) throws Exception {Thread stackOverflowErrorThread = new Thread(new Runnable() {@Overridepublic void run() {try {Thread.sleep(60000L);} catch (InterruptedException e) {e.printStackTrace();}// 进入死循环callRecursiveMethod();}}, "StackOverflowErrorThread");Thread otherNormalThread = new Thread(new Runnable() {@Overridepublic void run() {while (true) {System.out.println("I am otherNormalThread thread!!");try {Thread.sleep(10000L);} catch (InterruptedException e) {e.printStackTrace();}}}}, "otherNormalThread");stackOverflowErrorThread.start();otherNormalThread.start();Thread.currentThread().setName("mainThread");while (true) {System.out.println("I am main thread!!");try {Thread.sleep(10000L);} catch (InterruptedException e) {e.printStackTrace();}}}/*** 死循环模拟StackOverflowError*/public static void callRecursiveMethod() {callRecursiveMethod();}}

未发生Stack Overflow之前
在这里插入图片描述
发生Stack Overflow之后
在这里插入图片描述

从输入日志也可以验证这一点:
在这里插入图片描述

参考:
https://blog.csdn.net/u011983531/article/details/79563162

相关文章:

  • 10-2 HNCST - 多线程4 - 线程同步Condition——python
  • 2023年,我在美国的这一年!
  • CSS Grid 和 Flexbox
  • kivy开发一个登陆界面
  • 12.30_黑马数据结构与算法笔记Java
  • Java:IO流——字节流和字符流
  • Qlib从入门到精通
  • 2022年全国职业院校技能大赛高职组云计算正式赛卷第三场-公有云
  • pytorch01:概念、张量操作、线性回归与逻辑回归
  • 【论文阅读】Realtime multi-person 2d pose estimation using part affinity fields
  • x-cmd-pkg | 音视频处理领域中常用的开源转换工具:ffmpeg
  • Kubernetes 学习总结(43)—— Kubernetes 从提交 deployment 到 pod 运行的全过程
  • SpringBoot 集成 Kafka消息中间件,Docker安装Kafka环境
  • Eureka相关面试题及答案
  • Jenkins 系列:Jenkins 安装(Windows、Mac、Centos)和简介
  • Mocha测试初探
  • Node 版本管理
  • v-if和v-for连用出现的问题
  • Vue学习第二天
  • 阿里中间件开源组件:Sentinel 0.2.0正式发布
  • 第十八天-企业应用架构模式-基本模式
  • 构建二叉树进行数值数组的去重及优化
  • 前端每日实战:61# 视频演示如何用纯 CSS 创作一只咖啡壶
  • 使用docker-compose进行多节点部署
  • 数据仓库的几种建模方法
  • 小程序、APP Store 需要的 SSL 证书是个什么东西?
  • 学习ES6 变量的解构赋值
  • 原创:新手布局福音!微信小程序使用flex的一些基础样式属性(一)
  • 原生 js 实现移动端 Touch 滑动反弹
  • 阿里云服务器如何修改远程端口?
  • 小白应该如何快速入门阿里云服务器,新手使用ECS的方法 ...
  • ${ }的特别功能
  • (0)Nginx 功能特性
  • (02)vite环境变量配置
  • (17)Hive ——MR任务的map与reduce个数由什么决定?
  • (6)设计一个TimeMap
  • (二)丶RabbitMQ的六大核心
  • (十一)JAVA springboot ssm b2b2c多用户商城系统源码:服务网关Zuul高级篇
  • (译)2019年前端性能优化清单 — 下篇
  • (转)Java socket中关闭IO流后,发生什么事?(以关闭输出流为例) .
  • .net core MVC 通过 Filters 过滤器拦截请求及响应内容
  • .Net MVC4 上传大文件,并保存表单
  • .NET 分布式技术比较
  • .NetCore项目nginx发布
  • .NET建议使用的大小写命名原则
  • :not(:first-child)和:not(:last-child)的用法
  • @configuration注解_2w字长文给你讲透了配置类为什么要添加 @Configuration注解
  • @ModelAttribute注解使用
  • [AIGC] Java 和 Kotlin 的区别
  • [AutoSar]工程中的cpuload陷阱(三)测试
  • [C#小技巧]如何捕捉上升沿和下降沿
  • [docker] Docker的数据卷、数据卷容器,容器互联
  • [EFI]Atermiter X99 Turbo D4 E5-2630v3电脑 Hackintosh 黑苹果efi引导文件
  • [i.MX]飞思卡尔IMX6处理器的GPIO-IOMUX_PAD说明
  • [leetcode] 103. 二叉树的锯齿形层次遍历