How do I set Java's min and max heap size through environment variables?

后端 未结 7 1868
抹茶落季
抹茶落季 2020-11-29 00:48

How do I set Java\'s min and max heap size through environment variables?

I know that the heap sizes can be set when launching java, but I would like to have this ad

7条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 01:37

    A couple of notes:

    1. Apache ant doesn't know anything about JAVA_OPTS, while Tomcat's startup scripts do. For Apache ant, use ANT_OPTS to affect the environment for the JVM that runs /ant/, but not for the things that ant might launch.

    2. The maximum heap size you can set depends entirely on the environment: for most 32-bit systems, the maximum amount of heap space you can request, regardless of available memory, is in the 2GiB range. The largest heap on a 64-bit system is "really big". Also, you are practically limited by physical memory as well, since the heap is managed by the JVM and you don't want a lot of swapping going on to the disk.

    3. For server environments, you typically want to set -Xms and -Xmx to the same value: this will fix the size of the heap at a certain size and the garbage collector has less work to do because the heap will never have to be re-sized.

提交回复
热议问题