S
slubowsky
I have a little test program that simply loops creating threads and
then interrupts them. On my windows XP box with java 1.5.0 it hangs the
JVM with the following exception
Created 7124 threads
Exception in thread "main" java.lang.OutOfMemoryError: unable to create
new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Unknown Source)
at ThreadTest.main(ThreadTest.java:25)
What is going on here? Why is the JVM (apparently)not reclaiming the
thread memory after it dies?
See below for simple test program
Stephen
import java.lang.Thread.*;
public class ThreadTest
{
public static void main(String [] args)
{
int successfulThreadCreations = 0;
while(true)
{
try
{
Thread thread = new Thread(new Runnable()
{
public void run()
{
int x = 0;
while(true)
{
x++;
try{Thread.sleep(25);}
catch(InterruptedException e){}
}
}
});
thread.start();
System.out.println("Created
"+(++successfulThreadCreations)+" threads");
try{Thread.sleep(100);}
catch(InterruptedException e){}
thread.interrupt();
}
catch(Exception e)
{
System.out.println("Died with exception " + e + " after
creating "+successfulThreadCreations+" threads");
}
}
}
}
then interrupts them. On my windows XP box with java 1.5.0 it hangs the
JVM with the following exception
Created 7124 threads
Exception in thread "main" java.lang.OutOfMemoryError: unable to create
new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Unknown Source)
at ThreadTest.main(ThreadTest.java:25)
What is going on here? Why is the JVM (apparently)not reclaiming the
thread memory after it dies?
See below for simple test program
Stephen
import java.lang.Thread.*;
public class ThreadTest
{
public static void main(String [] args)
{
int successfulThreadCreations = 0;
while(true)
{
try
{
Thread thread = new Thread(new Runnable()
{
public void run()
{
int x = 0;
while(true)
{
x++;
try{Thread.sleep(25);}
catch(InterruptedException e){}
}
}
});
thread.start();
System.out.println("Created
"+(++successfulThreadCreations)+" threads");
try{Thread.sleep(100);}
catch(InterruptedException e){}
thread.interrupt();
}
catch(Exception e)
{
System.out.println("Died with exception " + e + " after
creating "+successfulThreadCreations+" threads");
}
}
}
}