2013-07-11 75 views
0

這是我的腳本(我只是想嘗試解決一個更大的問題):Java需要啓動多少內存?

#!/bin/bash 
JAVA_OPTS="-Xms64m -Xmx64m" 
for i in 1 2 3 4 5 6 7 8 9 10 
do 
    /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java -version & 
done 

概括地說,我試圖在同一時間啓動10個Java進程。服務器有512Mb的RAM和4Gb的交換。對於每個64Mb的十個進程來說,這應該足夠了。但是,這是我在其中兩個輸出中看到的:

Error occurred during initialization of VM 
Could not reserve enough space for the card marking array 
Error occurred during initialization of VM 
Could not reserve enough space for code cache 

爲什麼會發生這種情況?如何解決?

崩潰進程創造了這個啓動文件:

# There is insufficient memory for the Java Runtime Environment to continue. 
# Native memory allocation (malloc) failed to allocate 160088 bytes for HashtableBucket in /build/buildd/openjdk-7-7u21-2.3.9/build/openjdk/hotspot/src/share/vm/utilities/hashtable.inline.hpp 
# Possible reasons: 
# The system is out of physical RAM or swap space 
# In 32 bit mode, the process size limit was hit 
# Possible solutions: 
# Reduce memory load on the system 
# Increase physical memory or swap space 
# Check if swap backing store is full 
# Use 64 bit Java on a 64 bit OS 
# Decrease Java heap size (-Xmx/-Xms) 
# Decrease number of Java threads 
# Decrease Java thread stack sizes (-Xss) 
# Set larger code cache with -XX:ReservedCodeCacheSize= 

下列哪項是我的情況?

+0

我不知道這件事,但是我認爲,當你啓動一個JVM,它需要在啓動時args中給出了所有的記憶。因此,你需要640M ... –

+0

你的意思爲4GB該交換不被視爲內存JVM? – yegor256

+0

'-Xmx'定義了最大堆大小 - 整個Java進程使用的內存比這個大。 – assylias

回答

0

的Java保留在啓動對虛擬機的內部管理一些內存必須是物理內存(不交換)。如果您沒有足夠的物理內存,JVM將無法啓動。

+0

它是一個可配置的參數?你能給一些鏈接解釋這個請嗎? – yegor256

+0

@ yegor256沒有沒有參數,我沒有發現這方面的任何引用。但是有些結構需要記憶,但正如我所說,我沒有找到任何參考。 –

相關問題