Reputation: 18035
Does a JVM exit when a stack overflow exception occurs in one of the executing threads?
Upvotes: 1
Views: 582
Reputation: 28293
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.
Upvotes: 3