OutOfMemoryError creating a thread

The java.lang.OutOfMemoryError: Failed to create a thread message occurs when the system does not have enough resources to create a new thread.

There are two possible causes of the java.lang.OutOfMemoryError: Failed to create a thread message:
  • There are too many threads running and the system has run out of internal resources to create new threads.
  • The system has run out of native memory to use for the new thread. Threads require a native memory for internal JVM structures, a Java™ stack, and a native stack.
To correct the problem, either:
  • Increase the amount of native memory available by decreasing the size of the Java heap using the -Xmx option.
  • Reduce the number of threads in your application.