Home

Xmx2g

Xmx2g refers to the Java Virtual Machine's maximum heap size set to 2 gigabytes using the -Xmx option. The Java heap is the area of memory used for allocating Java objects and related runtime data. Setting -Xmx2g imposes an upper bound on how much memory the JVM will allocate for the heap, independent of the total physical memory available on the system. The -Xmx option can be combined with -Xms to specify the initial heap size as well (for example, -Xms512m -Xmx2g). Memory size units in the Xmx specification include k, m, and g, where 1g equals 1024m and 1m equals 1024k.

Usage example: java -Xms512m -Xmx2g -jar myapp.jar.

Platform considerations: On 32-bit JVMs, the practical maximum heap may be limited by address space, and starting

Impact and guidance: A larger heap can improve performance for memory-heavy applications but can increase garbage

a
process
with
-Xmx2g
can
fail
even
on
machines
with
abundant
RAM.
On
64-bit
JVMs,
allocating
2g
is
common,
provided
the
system
has
enough
free
memory
and
container
limits
allow
it.
The
total
memory
available
to
the
JVM
also
includes
non-heap
areas,
such
as
native
memory,
thread
stacks,
and
Metaspace
or
PermGen,
depending
on
the
Java
version
and
configuration.
collection
pauses
and
overall
memory
footprint.
It
is
recommended
to
set
-Xmx
based
on
profiling
results,
available
RAM,
and
other
processes
running
on
the
host,
and
to
monitor
heap
usage
with
appropriate
tools.