java.lang.OutOfMemoryError: unable to create new native thread

In JVM, each thread is allocated separate memory space called "thread stack", which is configured by JVM option "-Xss". The default value depends on OS/JVM. As number of threads increase, memory usage increases and can lead to 'out ofMemoryError'. Remember, the memory for threads is allocated on stack and not on Java Heap.


If you are getting this error, then you can try decreasing the memory allocated to heap (-Xmx) and/or decreasing the thread stack memory (-Xss). Increasing -Xmx (32bit systems) will leave less room for threads if it is being used, hence the opposite of the solution.

Remember the memory allocated using '-Xss' is the maximum memory allocated per thread, and usually it's in KB. Also too low -Xss value can cause java.lang.StackOverflowError. If you continue to get the same error, you probably have thread leak, fix the program.

Other OutOfMemoryErrors:

Comments *
Name *
Please Answer this simple math Question *(9 + 7) =

siddu thoda confusion hai rey mera bhai ...ek bar dhek ki new matter lagavo....
12 Sep 2012