增加java堆大小的步伐

时间:2015-04-11 12:12:13

标签: java linux

我需要将Java堆大小增加到2GB RAM。为了做同样的事情,我使用命令作为用户(我没有以root用户身份执行此操作):

$ export JVM_ARGS="-Xmx2048m"

但是,执行此操作后,Java堆大小不会增加。

$ java -XX:+PrintFlagsFinal -version | grep -iE 'HeapSize|PermSize|ThreadStackSize'
    uintx AdaptivePermSizeWeight                    = 20              {product}           
     intx CompilerThreadStackSize                   = 0               {pd product}        
    uintx ErgoHeapSizeLimit                         = 0               {product}           
    uintx HeapSizePerGCThread                       = 87241520        {product}           
    uintx InitialHeapSize                          := 1054841216      {product}           
    uintx LargePageHeapSizeThreshold                = 134217728       {product}           
    uintx MaxHeapSize                              := 16877879296     {product}           
    uintx MaxPermSize                               = 174063616       {pd product}        
    uintx PermSize                                  = 21757952        {pd product}        
     intx ThreadStackSize                           = 1024            {pd product}        
     intx VMThreadStackSize                         = 1024            {pd product}        
java version "1.7.0_75"
OpenJDK Runtime Environment (rhel-2.5.4.0.el6_6-x86_64 u75-b13)
OpenJDK 64-Bit Server VM (build 24.75-b04, mixed mode)

有人可以建议我哪里出错吗?

2 个答案:

答案 0 :(得分:1)

环境变量的名称为JAVA_TOOL_OPTIONS

$ export JAVA_TOOL_OPTIONS='-Xmx2G'
$ java -XX:+PrintFlagsFinal -version | grep -iE 'MaxHeapSize'
Picked up JAVA_TOOL_OPTIONS: -Xmx2G
    uintx MaxHeapSize                              := 2147483648                          {product}
openjdk version "1.8.0_40-internal"
OpenJDK Runtime Environment (build 1.8.0_40-internal-b27)
OpenJDK 64-Bit Server VM (build 25.40-b25, mixed mode)

答案 1 :(得分:0)

  1. 2048 in -Xmx2048m表示2048 MB(2GB),因此对于4GB,您将不得不使用-Xmx4096m
  2. 现在您没有向java提供参数,为此,您必须按如下方式运行它:
  3. java -Xmx4096m

    对于你的例子:

    java -Xmx4096m -XX:+PrintFlagsFinal -version | grep -iE 'HeapSize|PermSize|ThreadStackSize'