Does a JVM exit when a stackoverflow exception occurs in one of the executing threads?
Does a JVM exit when a stack overflow 开发者_运维技巧exception occurs in one of the executing threads?
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):
public class SO {
private static void a() {
a();
}
public static void main(String[] args) throws InterruptedException {
final Thread t = new Thread( new Runnable() {
public void run() {
a();
}
});
t.start();
while ( true ) {
Thread.sleep( 2000 );
System.out.println( "I'm still running @ " + System.currentTimeMillis() );
}
}
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.
精彩评论