Maximum number of threads in a JVM

Out of curitosity, I thought it would be interesting to know the maximum number of threads I could squeeze out of a JVM on various platforms. From an old thread on Stack Overflow, I knew that different JVM implementations had different limits. So, I whipped up this little Java program and ran it on various platforms. 

import java.util.concurrent.atomic.AtomicInteger;

public class ThreadCounter extends Thread {
	private static final AtomicInteger count = new AtomicInteger();
	
	public static void main(String[] args) {
		while (true)
			(new ThreadCounter()).start();
			
	}

	@Override
	public void run() {
		System.out.println(count.incrementAndGet());
		
		while (true)
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				break;
			}
	}
}

Compile and run at the command line: 

  javac ThreadCounter.java
  java  -cp . ThreadCounter

The results:

Hardware OS JVM Count
2010 i5 MBP, 4GB OSX 10.6 Apple 1.6.0_22-b04-307 2540
Xeon 5120, 4GB Debian Lenny 64-bit Sun 1.6.0_12-b04 31618
EC2 m1.small, 1.7GB Ubuntu 10.04 32-bit OpenJDK IcedTea6 1.8.2 7452
Atom 330, 2GB Windows XP SP3 Sun 1.6.0_27-b07 5165
EC2 c1.medium, 1.7GB Ubuntu 10.04 32-bit OpenJDK IcedTea6 1.8 7029

Interesting…