Does a JVM exit when a stack overflow exception occurs in one of the executing threads?
views:
57answers:
1
+3
A:
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.
Webinator
2010-02-12 20:42:18
what does "EDT" mean?
matt b
2010-02-12 20:54:07
I think it's the "event dispatcher thread" for AWT.
Johannes Schaub - litb
2010-02-12 21:00:01