当正在执行的线程之一发生 stackoverflow 异常时,JVM 是否会退出?
当正在执行的线程之一发生堆栈溢出异常时,JVM 是否会退出?
Does a JVM exit when a stack overflow exception occurs in one of the executing threads?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以自己尝试使用,例如使用以下代码(生成并启动一个新线程并调用
a()
,它递归地调用自身以触发堆栈溢出,而另一个线程将某些内容打印到控制台):您将看到堆栈溢出错误:
Exception in thread "Thread-1" java.lang.StackOverflowError
并且您还将看到打印线程继续愉快地打印。
另请注意,如果 EDT 线程终止,它会自动重新启动。
You can try it for yourself using, for example with the following code (a new thread is spawned and started and calls
a()
which calls itself recursively as to trigger a stack overflow while another thread prints something to the console):You'll see your stack overflow error:
Exception in thread "Thread-1" java.lang.StackOverflowError
and you'll also see that the printing thread keeps happily printing along.
Also note that if the EDT thread dies, it is relaunched automagically.