I faced the below issue in my application java.lang.OutOfMemoryError: unable to create new native thread
My development environment in windows 7 64bit and deployment environment in linux 64 bit. I could not recreate the issue in my local development environment. I got the below code which when I ran in linux server gave me the same error when thread 3993 was created. ulimit -u
gave a count of 4096. So I am convinced that somewhere near this threshold new threads are not allowed to be created for the process/application/user.
However I couldn't recreate the issue in my windows development environment. I am curious what code would actually give me the thread threshhold in windows
public class ThreadLimitChecker
{
public static void main(String[] args)
{
System.out.println("Hello World");
int count = 0;
while (true)
{
count++;
new Thread(new Runnable()
{
public void run()
{
try
{
Thread.sleep(10000000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
System.out.println("Thread #:" + count);
}
}
}
Expected a thread number where exception occurs