日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java 线程栈空间_java线程的内存不包含在JVM堆与栈中

發布時間:2025/3/19 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 线程栈空间_java线程的内存不包含在JVM堆与栈中 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Java代碼 ?

publicclassMaxThreadsTest?{

publicstaticvoidmain(String[]?args)?{

while(true)?{

newThread(newA()).start();

if(A.eflag.get()){

return;

}

}

}

}

classAimplementsRunnable?{

staticAtomicInteger?counts?=newAtomicInteger(0);

staticAtomicBoolean?eflag?=newAtomicBoolean(false);

@Override

publicvoidrun()?{

try{

intx?=?counts.getAndIncrement();

if(x%200==0)

System.out.println("conts:?"+?A.counts);

Thread.sleep(30000);

}catch(InterruptedException?e)?{

eflag.set(true);

e.printStackTrace();

}

}

}

public class MaxThreadsTest {

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 0==0)

System.out.println("conts: " + A.counts);

Thread.sleep(30000);

} catch (InterruptedException e) {

eflag.set(true);

e.printStackTrace();

}

}

}

Java代碼 ?

-Xms16M?-Xmx32M?-Xss1M?-XX:+HeapDumpOnOutOfMemoryError

conts:1801

Exception?in?thread"main"java.lang.OutOfMemoryError:?unable?to?createnewnativethread

-Xms32M?-Xmx64M?-Xss1M?-XX:+HeapDumpOnOutOfMemoryError

conts:1801

Exception?in?thread"main"java.lang.OutOfMemoryError:?unable?to?createnewnativethread

//把Xmx設大可以建立的線程數反而變小,這是個很奇怪的事情:

-Xms64M?-Xmx128M?-Xss1M?-XX:+HeapDumpOnOutOfMemoryError

conts:1601

Exception?in?thread"main"java.lang.OutOfMemoryError:?unable?to?createnewnativethread

//把Xmx設大可以建立的線程數反而變小,這是個很奇怪的事情:

-Xms128M?-Xmx256M?-Xss1M?-XX:+HeapDumpOnOutOfMemoryError

conts:1601

Exception?in?thread"main"java.lang.OutOfMemoryError:?unable?to?createnewnativethread

//把Xss設小有驚人效果:

-Xms16M?-Xmx32M?-Xss128K?-XX:+HeapDumpOnOutOfMemoryError

conts:13401

Exception?in?thread"main"java.lang.OutOfMemoryError:?unable?to?createnewnativethread

-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越小,則線程數越多么?

被移到問答區里了,這么低的懸賞,能有人關注嗎?

沒辦法了,就這么點錢啦……………………………………………………………………

2010-12-17 flootball (高級程序員)

你的操作系統的內存是多少?

在java中每new一個線程,jvm都是向操作系統請求new一個本地線程,此時操作系統會使用剩余的內存空間來為線程分配內存,而不是使用jvm的內存。這樣,當操作系統的可用內存越少,則jvm可用創建的新線程也就越少。

總結

以上是生活随笔為你收集整理的java 线程栈空间_java线程的内存不包含在JVM堆与栈中的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。