About JVM Heap Sizing

I developed an application for communication using streams. but when I start my application system, it works very slowly, and sometimes an exception occurs that the heap is full. I want to increase the heap size of a Java virtual machine. How can i do this?

+4
source share
4 answers

Just increase the heap size of the JVM. All Java applications, even simple ones, consume a lot of memory. Take a look at the article , which explains in detail how to increase the amount of available memory for your application; basically you need to pass a few extra JVM parameters when calling the java command, for example:

 java -Xms64m -Xmx256m HelloWorld 

In the command above, I say that HelloWorld should have an initial heap size of 64 MB and a maximum of 256 MB. Try these values ​​and play around with them a bit until you find a combination of values ​​that work for your application.

+5
source

You can increase the heap size, but your big problem is: "Why did I get this exception?" Increasing the size of the heap will only delay the inevitable if your application does not clean up properly after itself.

You need to configure the application on Visual VM and see what happens. This will give you more way forward than just increasing the size of the heap.

+3
source

Add -Xmx100m to the command when starting the application. This will give you a 100 megabyte heap (you can change the number).

It sounds strange that a chat application would require more than the standard heap size ...

+2
source

Blockquote

Large server applications often experience two problems with these by default. One of them is a slow start, since the initial heap is small and needs to be changed across many major collections. A more pressing issue is that the default maximum heap size is unreasonably small for most server applications.

Blockquote

You can start your program using the command line using these parameters java -Xms64m -Xmx256m chat_program. Here Xms64m = 64 MB of the initial heap size and Xmx256m = maximum heap size of 256 MB

+1
source

Source: https://habr.com/ru/post/1402442/


All Articles