Java需要多少内存才能启动?

时间:2013-07-11 09:52:02

标签: java ubuntu memory-management

这是我的脚本(我只是想尝试解决一个更大的问题):

#!/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=

以下哪一项是我的理由?

1 个答案:

答案 0 :(得分:0)

Java会在启动时为内部管理VM保留一些必须是物理内存(而不是交换)的内存。如果没有足够的物理内存,JVM将无法启动。

相关问题