public class MaxThreadsTest { /** * @param args */ public static void main(String[] args) { while (true) { new Thread(new A()).start(); if(A.eflag.get()){ return; } } } } class A implements Runnable { static AtomicInteger counts = new AtomicInteger(0); static AtomicBoolean eflag = new AtomicBoolean(false); @Override public void run() { try { int x = counts.getAndIncrement(); if(x%200==0) System.out.println("conts: " + A.counts); Thread.sleep(30000); } catch (InterruptedException e) { eflag.set(true); e.printStackTrace(); } } }
-Xms16M -Xmx32M -Xss1M -XX:+HeapDumpOnOutOfMemoryError conts: 1801 Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread -Xms32M -Xmx64M -Xss1M -XX:+HeapDumpOnOutOfMemoryError conts: 1801 Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread //把Xmx设大可以建立的线程数反而变小,这是个很奇怪的事情: -Xms64M -Xmx128M -Xss1M -XX:+HeapDumpOnOutOfMemoryError conts: 1601 Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread //把Xmx设大可以建立的线程数反而变小,这是个很奇怪的事情: -Xms128M -Xmx256M -Xss1M -XX:+HeapDumpOnOutOfMemoryError conts: 1601 Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread //把Xss设小有惊人效果: -Xms16M -Xmx32M -Xss128K -XX:+HeapDumpOnOutOfMemoryError conts: 13401 Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread
以上是在eclipse里测试的。
在windows下直接测试有明显不同。
java MaxThreadsTest -Xms16M -Xmx32M -Xss1M
java MaxThreadsTest -Xms64M -Xmx128M -Xss1M
无论怎么设置都在5401后结束。
我对JVM的了解基本为0,所以也分析不出原因。
请大家帮我看看,这是怎么回事,不是说Xmx越大、Xss越小,则线程数越多么?
被移到问答区里了,这么低的悬赏,能有人关注吗?
没办法了,就这么点钱啦……………………………………………………………………