Give me an example

The following example creates and starts new threads in a loop. When running the code, operating system limits are reached fast and java.lang.OutOfMemoryError: Unable to create new native thread message is displayed.

64-bit Windows 7, Java 1.7.0_45 – due to a different thread model used by the OS, this error seems not to be thrown on this particular platform. On thread #250,000 the process was still alive, even though the swap file had grown to 10GB and the application was facing extreme performance issues.

So make sure you know your limits by invoking a small test and find out when the java.lang.OutOfMemoryError: Unable to create new native thread will be triggered