Home | Login | Blog | Forum | Download | RSS Feed | Ajax | Hello-World | J2EE | BPM | EJB | FileNet | Hibernate | ORM | IBM | ILOG | Interview | FAQs |

Java | Apache | JVM | Others | BRMS | Oracle | Pega | SOA | Sun-Certification | Web-Service | websphere | XML |
 

JAVA DEVELOPER SITE - COMPLETE JAVA TUTORIALS

What is Java Heap Size & java.lang.OutOfMemoryError


Share
 
 

Useful Java Links


       


Each time object is created in Java it goes into the area of memory known as heap. In a multithreaded application each thread will have its own stack but will share the same heap. This is  why care should be taken in our code to avoid any  concurrent access issues in the heap space.

 

The heap may be of a fixed size or may be expanded. The heap is created on virtual machine start-up. If we have complicated programs or  big caching which might create lot of objects in memory so we may need bigger heap size. In this case it is possible that JVM  will throw java.lang.OutOfMemoryError instances when attempting to instantiate objects.

 

 We can increase heap size using the following command

 

java -Xms64m -Xmx256m MyProgram

 

Here we are setting minimum heap to 64MB and maximum heap to 256MB for a Java program MyProgram.

 

Following are the options available for changing the Java heap size

-Xms<size>        set initial Java heap size

-Xmx<size>        set maximum Java heap size

-Xss<size>        set java thread stack size

 

Reading Default Heap size

We can get to know how large the object heap is and  how much of it is left, using the methods provided by Runtime class. Runtime  class encapsulates the running Java interpreter process. We can use totalMemory and freeMemory methods in Runtime to get the information.

 

public class MyprogramHeapSize {

            public static void main(String[]args){

                        //Get the jvm heap size.

                        long heapSize = Runtime.getRuntime().totalMemory();

                        //Print the jvm heap size.

                        System.out.println("Heap Size = "+heapSize);

            }

 

}

 

 

Output of this program is

Heap Size = 55312384




Download Latest Java/J2EE eBooks, SCJP Dumps, SCWCD Dumps, Pega Tutorial, IBM WebSphere BPM tutorials and many more


If you need any urgent assistance on java-heap-size-OutOfMemoryError-exception, kindly email your requirement to us at : info@javagenious.com or Contact-an-Expert. Our experts will try their best to solve your problem.

You can also subscribe to our newsletters on java-heap-size-OutOfMemoryError-exception, to receive updates on java-heap-size-OutOfMemoryError-exception,via email.Enter you email below:

Enter your email address:

Delivered by FeedBurner



Keyword Tags: java-heap-size-OutOfMemoryError-exception tutorial,java-heap-size-OutOfMemoryError-exception in java,Concepts of java-heap-size-OutOfMemoryError-exception,Java,J2EE,Interview Questions,java-heap-size-OutOfMemoryError-exception Examples


Comments:


Post Your Comment:

*

Yes, I would like to recieve email notifications on my reply.

Popular Posts:

 
Popular Downloads

SCJP 1.6 Dumps
JSP Interview Questions
Struts Interview Questions
Hibernate Interview Questions
SCWCD Dumps
SCBCD Dumps

Java/J2EE Tutorial
JMS Tutorials
seam richfaces tutorial
richfaces live demo
jquery example demo
JQuery Tutorial and Source Code
JSF Tutorial
XSL Tutorial
J2EE JMS
CORBA Applications
Java CERTIFICATION
SCJP 1.5
SCJP 1.6
SCWCD 1.5
SCBCD
Mis
Ajax autosuggest autocomplete from database
Struts forms and validation with webflow
Java Apache POI Examples
JDBC Tutorial
Oracle 9i & 10g
MYSQL Tutorial
php Tutorial
JQuery Examples
Upload Java File
JAXB Examples
PL-SQL Tutorial
Dojo AJAX
EJB Examples
Java IDE
Eclipse
NetBeans
IBM Rational Weblogic Workshop
Downloads
SCJP 1.6 Dumps
SCJP 1.5 DUMP
SCJP Material
SCWCD
Java Security
SCBCD Dumps
External Links
SUN Java
JOracle
IBM
PHP Certification
Technical Interview Questions
Amazon Interview Questions
Google Interview Questions
Microsoft Interview Questions
IBM Interview Questions
Yahoo Interview Questions
All Tutorials
php mysql tutorial
SCJP 1.5/1.6
SCWCD 1.5/1.6
Polymorphism
Thread Tutorial
Generics & Exceptions
Spring Struts Hibernate
Java Collections
MAP
SET
LIST
VECTOR
Advanced Java
Stateless Session Bean
Introduction to EJB
Stateful Session Bean
Java Design Patterns
HOME | FORUM | ABOUT | BLOGS | CONTACT-US