Saturday, October 31, 2009

Java Memory Arrangements

Java Memory Arrangements

Java Memory is splitted in to three generation - Young Generation, Tenured Generation, and Permanent Generation.

  • Young Generation

    Infant mortality data are get stored in young generation, means any new objects created and stored here. This has One Eden and two survivor spaces, where one survivor space always empty. If data get filled in survivor space and ready to long live then it will be copied to Eden space. Usually in Solaris, two equal space alotted for eden and survivorspace.

    Once the Eden space get filled then Minor Collections(Garbage Collections) get triggered and tenured objects will be copied to Tenured Generation.

    Specifying bigger young generation for the application which does have more infant moratality objects, would give better performance.

  • Tenured Generation

    Long live tenured objects will be stored in this space. Once the Tenured generation get filled then Major collections(Garbage Collections) will be triggered. This collection costs more, because of the fact that it will operate on all long living objects. In general, keeping more space for long running applications like Application Server , would result better performance.

    Major and Minor collections happened based on the tuning parameters set. In general, 40% of Heap(-Xmx) filled then major collections starts and shrinks up to -Xms value. This percentage can be reset using -XX:MinHeapFreeRatio. If the application shrinks and expands the memory allocation (malloc) then this will cost the performance. Hence, this has to be controlled and set using -XX:MaxHeapFreeRatio to some percentage, which always application needed size in the entire tenure.

    Keeping -Xms and -Xmx value equal will result better performance for GUI, and server applications.

  • Permanent Generation

    Loaded classes and Classe definitions are get stored in this space. In general, this space will be occupied in physical memory while application start up based on the value of -XX:PermSize. Maximum size permanent generation space can be set by -XX:MaxPermSize.

    If the application has more number of classes and object has to be created/loaded at the given point of time then this space has to be set high. Even this property helps to improve the performance and avoids OutOfMemoryError, which comes for PermGen space full.

Java Application Memory= Heap + PermGen Space.

In JRocket, there is no concept of PermGen Space. Hence, JRocket users no need of worrying about these properties.

OW2 Consortium : ASM 3.0

OW2 Consortium : ASM 3.0

ASM is nice tool to decompile the class files and also helps us to manupulate and modify the class files directly without modifying the original JAVA source. This tool usefull for instrumenting jars like,

  • Adding debug statements - on need basis without modifying the original source
  • Correcting particular line of code directly in testing environment where we do not have original source.
  • and lot more...

Even ASM provides plugin which helps seemlessly converts class file and which helps us to compare the actual and compiled format code.

Check the following URL

Friday, October 30, 2009

Performance : List and Set

In List interface implementations, before adding the data and to avoid duplication, we need to make a check whether already the data exist in the list. List implementation will nicely work <5000 entry, we do not see much of performance different, not more than milliseconds different.

Once we started adding more entries and started doing manipulations, we will be in position to ask questions and answer ourself, what went wrong, what could be the alternate. Cool..., Here you go.

Now, we think of Set interface and implementations. All the Set implementations avoids duplicate entries and also reports back to caller with boolean value - true, if this set did not already contain the specified element.

These Set interface implementation gives best performance in huge data and comes with different flavours

No guarantee for order in which added,and no guarantee for order based on the value.
Guaranteed order in which added.
SortedSet Implementation - Guaranteed Ascending order on value.

HashSet = [9, 25, 4, 36, 100, 1, 49, 81, 16, 64]
LinkedHashSet = [100, 81, 64, 49, 36, 25, 16, 9, 4, 1]
TreeSet = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

Performance wise HashSet gives best ,and LinkedHashSet in second position, and TreeSet.

However, Based on the need/usage, any of these Set implementation has to be used :)

Please refer for more details -

Tuesday, October 27, 2009

Java Network Proxy Settings

If our application wants to access external content where our system needs to go through proxy server, then we have to give http proxy details to access via proxy server.

For instance, to enable proxy for xdk tool, set -Dhttp.proxyHost , -Dhttp.proxyPort as below

java -cp .\xml.jar;.\xmlparserv2.jar -Dhttp.proxyPort=80 oracle.xml.parser.v2.oraxml -schema abcd.xml

Please find more details

Tuesday, October 6, 2009

JAXB version attribute must be present

Add/set jaxb:version attribute in schema tag to avoid this exception

jaxb:version="1.0" elementFormDefault="qualified">

Monday, October 5, 2009

Oracle XDK : XML Validation - Schema DTD

Command to validate XML against schema using Oracle XDK

java -cp .\xml.jar;.\xmlparserv2.jar oracle.xml.parser.v2.oraxml -schema /tmp/abcd.xml

Refer for more details

Recent Posts

Unix Commands | List all My Posts


This blog intended to share the knowledge and contribute to JAVA Community such a way that by providing samples and pointing right documents/webpages. We try to give our knowledege level best and no guarantee can be claimed on truth. Copyright and Terms of Policy refer