Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java increase xmx dynamically at runtime

I have a jvm server in my machine, now I want to have 2 apservers of mine sitting in same machine, however I want the standby one to have a really low amount of memory allocated with xmx because its passive, one the main server (active) goes down I want to allocate more memory to my passive server which is already up without restarting it (I have have them both having too much xmx - note they would consume memory at startup and I cant allow possibility of outOfMemory).

So I want passive - low xmx once active goes down I want my passive to receive much more xmx.

is there a way for me to achieve that. Thanks

like image 764
Jas Avatar asked May 21 '10 17:05

Jas


People also ask

Can Java exceed XMX?

java - JVM exceeds maximum memory defined with -Xmx - Stack Overflow. Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.

Is heap size dynamic?

Heap memory is dynamic, like stack memory, in that it is allocated at run time.

Can XMS be greater than XMX?

The -Xmx option and -Xms option in combination are used to limit the Java heap size. The Java heap can never grow larger than -Xmx . Also, the -Xms value can be used as “minimum heap size” to set a fixed heap size by setting -Xms = -Xmx . However -Xmx does not limit the total amount of memory that the JVM can use.


1 Answers

It would be nice, but as far as I know it's not an option with the Sun provided JVMs.

The Xmx option is to specify maximum memory, it's there to prevent the JVM from consuming the entire machine's free memory. If you want to set it higher, it won't require the JVM allocate all of that memory. Why not just set it to a very high number and let the JVM grow into it over time?

To make sure your JVM doesn't start off with too little memory (creating lots of pauses as it grows the memory to the required size), adjust Xms to the size you want to allocate for the JVM at startup.

like image 134
Edwin Buck Avatar answered Sep 20 '22 15:09

Edwin Buck