Saturday 6 August 2016

ClassLoader in java

For the past few weeks, many questions related to ClassLoader were popping in my mind.Lets discuss these questions that I will try answer in this blog.

  • When do you need a custom classloader ?
  • If classes are loaded by classloaders , then who is responsible for loading classes of ClassLoader itself ?
  • Can a single class be loaded with different classLoaders?
  • Can Objects of same class loaded by different classloaders be compared?
  • How loadClass(String) method in ClassLoader works ?
Lets try to answer these and many other questions.

Sunday 29 May 2016

Understanding CGLIB

CGLIB is a byte code generation library which creates and link proxy classes at runtime.As java classes can be dynamically linked , we can add new classes in running java program.It simply creates a subclass of your class by reading its byte code. Under the hood it uses ASM which is a byte code manipulation framework. ASM helps CGLIB to generate java byte code at runtime.

Frameworks like spring, hibernate, mockito uses CGLIB. Spring AOP uses proxy-based Aspect Oriented Programming which has a feature of method interception.Hibernate implemented a feature of returning proxy of an object of entity graph from database where child entities are fetched from database when required.Hibernate uses CGLIB for this feature.

Lets start with some coding examples. CGLIB has a class named Enhancer which helps us to create proxy class for all the classes implementing or not implementing any interface. It is quite similar to Proxy class in java.

Thursday 17 March 2016

How Hibernate cache works

After working on performance of web applications , I realized its time to share my learning of hibernate with all of you.
There are three terminologies used with hibernate cache :

  • Hibernate first level cache
  • Hibernate second level cache
  • Hibernate query cache