Patrick
Patrick

Reputation: 1019

How to handle java.lang.OutOfMemoryError

I am running a makefile and after a while I get the following error:

 java.lang.OutOfMemoryError

I am wondering whether there is a command that allows me to increase the Java Heap Space. I dont want to change the makefile itself, so I need some kind of "global" command that allows me to reset the Java Heap Space.

Many thanks, Patrick

EDIT: Thanks for your answers. But I am looking for a more global command, that allows me to specify to set the Heap space once and for all like:

SET JAVA_HEAP_SPACE = 5GB

Thanks

Upvotes: 1

Views: 724

Answers (3)

Juvanis
Juvanis

Reputation: 25950

  • You can set java heap space from command line: java -Xmx1600m program Now your heap space is 1600 MB.(Assuming your hardware can already afford 1600MB.)

  • For Windows platforms, you can set it from Java Runtime Environment Settings as well. Follow Control Panel => Programs => Java. Navigate to Java tab. View Java Runtime Environment Settings. Add -Xmx1600m to Runtime Parameters. Save and go on.

  • For Linux platforms, you can launch Control Panel and edit runtime parameters. It can be run from something like /usr/j2se/jre/bin/ControlPanel. Find your own directory. Read here please: http://docs.oracle.com/javase/7/docs/technotes/guides/deployment/deployment-guide/jcp.html

Upvotes: 4

Parvin Gasimzade
Parvin Gasimzade

Reputation: 26012

You can use the following command :

java -Xms64m -Xmx256m ClassName
Xms<size>        set initial Java heap size
Xmx<size>        set maximum Java heap size

In this example, initial heap size set to 64MB and maximum heap size is set to 256MB. For more information check this.

Upvotes: 1

Saurabh
Saurabh

Reputation: 7964

question is not very clear However you should look at -Xmx flag as the JVM startup parameter to make more memory available to your application. Please read here for more on this. You should also do profiling of you Java application and see where the most of the available memory is being consumed. You can make use of JProfiler (just google about the tools to profile you Java application) to profile and see the statistics about which part of application is consuming more systems resource.

Upvotes: 0

Related Questions