Vinay
Vinay

Reputation: 347

about increasing heap size of JVM

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?

Upvotes: 4

Views: 10782

Answers (4)

Zhivko Draganov
Zhivko Draganov

Reputation: 1253

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

Upvotes: 1

Óscar López
Óscar López

Reputation: 235984

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.

Upvotes: 5

duffymo
duffymo

Reputation: 308733

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.

Upvotes: 3

Mathias Schwarz
Mathias Schwarz

Reputation: 7197

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...

Upvotes: 2

Related Questions