4

i have developed chatting application using threads. but when i start my application system acts very slow and sometime exception occur that heap is full. i want to increase heap size of Java Virtual Machine. how can i do it?

Vinay
  • 347
  • 1
  • 7
  • 16
  • 1
    this might be helpful to you http://stackoverflow.com/questions/880855/increase-the-java-heap-size-permanently – kunal Mar 20 '12 at 13:48

4 Answers4

5

Just increase the heap size of the JVM. All Java applications, even simple ones, consume a lot of memory. Take a look at this article explaining in detail how to increase the amount of memory available for your application; basically you'll need to pass a couple of extra parameters to the JVM when you invoke the java command, like this:

java -Xms64m -Xmx256m HelloWorld

In the above command, I'm saying that the HelloWorld program should have an initial heap size of 64MB and a maximum of 256MB. Try with these values and fiddle a bit with them until you find a combination of values that works for your application.

Óscar López
  • 232,561
  • 37
  • 312
  • 386
3

You can increase heap size, but your larger issue is "Why did I get that exception?" Increasing the heap size will only delay the inevitable if your application is not cleaning up after itself properly.

You need to instrument your application with Visual VM and see what's going on. That will give you more of a path forward than simply increasing the heap size.

duffymo
  • 305,152
  • 44
  • 369
  • 561
2

Add -Xmx100m to the command when you start your app. This will give you 100 MB heap (you can change the number).

It sounds strange that a chat app would required more than the standard heap size...

Mathias Schwarz
  • 7,099
  • 23
  • 28
  • my chat app is little bit huge including more functionality. i have executable jar of my app. then how can i do it? – Vinay Mar 20 '12 at 13:49
  • Something like `java -Xmx100m -jar yourjar.jar` should do it. – Mathias Schwarz Mar 20 '12 at 13:57
  • 'Functionality' will not necessarily take up heap space. Classes are loaded into the 'PermGen' part of the heap. I think you have 64MB heap by default. That is a lot of data. – Mathias Schwarz Mar 20 '12 at 13:59
1

Blockquote

Large server applications often experience two problems with these defaults. One is slow startup, because the initial heap is small and must be resized over many major collections. A more pressing problem is that the default maximum heap size is unreasonably small for most server applications.

Blockquote

You could start your program via command prompt with these parameters java -Xms64m -Xmx256m chat_program. Here Xms64m = 64mb initial heap size and Xmx256m = 256mb maximum heap size

Zhivko Draganov
  • 1,213
  • 2
  • 10
  • 16