Q: How many threads can be started by a single Java process?
A: It depends ...
You may use this very simple program ThreadStressTest.jar to test the limit on your system.On my Linux system (openSUSE 13.1, 8 GB RAM, QuadCore) the limit is at about 31 thousand threads.
Then an OutOfMemoryError occurs.
Obviously this value is independent of limits set by ulimit -u or JVM memory settings via -Xmx and -Xss.
USAGE:
java -jar StartThreads.jar <countOfThreadsToStart> <busySeconds>
EXAMPLE:
java -jar StartThreads.jar 1000 60
This command creates 1000 threads which all terminate after a minute.
The source code is included in the jar file.
Here comes a sample console session:
$ java -jar ThreadStressTest.jar 100000 10
Creating 100000 threads (1000 threads per dot) ....................................................................................................
Starting 100000 threads ............................... Problem while starting thread 31847. Skipping starting further threads.
java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:713)
at StartThreads.startThreads(StartThreads.java:52)
at StartThreads.start(StartThreads.java:21)
at StartThreads.main(StartThreads.java:8)
Waiting on termination of 100000 threads ....................................................................................................
Ready.
$
Further readings: StackOverflow