Reputation: 93
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
Upvotes: 2
Views: 1002
Reputation: 6732
Since I found this topic also interesting, I did some research.
You'll find the following statement by Mark Russinovich (CTO of Microsoft Azure by now) @ technet:
Unlike some UNIX variants, most resources in Windows have no fixed upper bound compiled into the operating system, but rather derive their limits based on basic operating system resources that I’ve already covered. Process and threads, for example, require physical memory, virtual memory, and pool memory, so the number of processes or threads that can be created on a given Windows system is ultimately determined by one of these resources, depending on the way that the processes or threads are created and which constraint is hit first.
So it's just running until there are no resources left.
Since ulimit
is more or less a piece of software which watches some metrics, there was (of course) a similar tool for Windows called Windows System Resource Manager (until Windows Server 2012) which was (according to Wikipedia) superseded by Hyper-V (since Windows Server 2008).
Upvotes: 5