Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java application to use maximum available memory in the system

Tags:

java

jvm

jnlp

There are -Xmx and max-heap-size (jnlp) options to set maximum memory java application can use.
If these options are not specified application is permitted to use only small amount of available phisical memory in the system.
That is the reason people play with -Xmx to allow application to use more memory. But this is really a nightmare as for me because there could be different amont of memory on client machine and even OS should be taken into consideration.

Is there any way to alow java application to use maximum available memory in the system?

Thanks.

like image 807
Mike Avatar asked Jul 06 '12 16:07

Mike


People also ask

How much memory does a Java application use?

By default, the HotSpot JVM will use up to 240MB. If the code cache is too small the JIT will run out of space to store its output and performance will suffer as a result. If the cache is too large, memory may be wasted.

Why is my Java application using so much memory?

Java is also a very high-level Object-Oriented programming language (OOP) which means that while the application code itself is much easier to maintain, the objects that are instantiated will use that much more memory.

Can Java use more memory than XMX?

Java consumes memory more than Xmx argument.


2 Answers

-XX:DefaultMaxRAMFraction=1

bugs.sun.com
Sun's 1.5 JVM
Default Heap Size

Doesn't work for web start.

like image 134
Mike Avatar answered Oct 07 '22 00:10

Mike


Unfortunately, the best way I'm aware of is to write a simple launcher (possibly a shell script or batch file) that inspects the system, determines an appropriate value for -Xmx, and then launches the Java application. Once the JVM has initialized, it is not possible to change the values.

like image 22
Steven Schlansker Avatar answered Oct 07 '22 02:10

Steven Schlansker