Solved

ClassLoaders in java

Posted on 2014-03-25
6
939 Views
Last Modified: 2014-04-03
Two objects loaded by different class loaders are never equal even if they carry the same values.
This means a class is uniquely identified in the context of the associated classloader. This applies to singletons too, where each classloader will have its own singleton.

I was reading as above. I have not understood what it means.
please advise
Any links resources ideas highly appreciated. Thanks in advance
0
Comment
Question by:gudii9
  • 3
  • 2
6 Comments
 
LVL 12

Expert Comment

by:Sharon Seth
ID: 39955749
I do not think two classloaders(on the same JVM) can load the same object , it wld create conflicts when trying to access the class. But the same object on different JVMs is possible.
0
 
LVL 35

Expert Comment

by:girionis
ID: 39958275
It means that a class can be loaded by two different classloaders, and in the context of the JVM these classes are considered *not* the same, even if, in fact, they are byte-for-byte the same class. So if you have a class A which is loaded by both classloader X and classloader Y then, as far as the JVM is concerned, you have *two different* classes. This is what the phrase
a class is uniquely identified in the context of the associated classloader
means.
0
 
LVL 7

Author Comment

by:gudii9
ID: 39973090
how is classloader is different or related to JVM. In which practical scenario this situation happens? I never come across this scenario earlier. please advise
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 35

Expert Comment

by:girionis
ID: 39974295
All classloaders are loaded by the JVM. When the JVM starts it loads the bootstrap classloader, and this in turn loads all other classes, including the rest of the classloaders that will load their own classes and so on.
0
 
LVL 12

Assisted Solution

by:Sharon Seth
Sharon Seth earned 100 total points
ID: 39974725
I still do not believe there will be a practical scenario where a class will be loades by two classloaders . Class loading is hierarchial , in the sense that a classloader first checks if a class is already loaded by another lower level class loader , before actually loading it .
0
 
LVL 35

Accepted Solution

by:
girionis earned 400 total points
ID: 39974767
A class is identified (among other things) in the context of the classloader as well. So two different classloader could load the same class twice. Here is a nice article on different ways you can get two different objects from two different classloaders.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JUnit 4 @Before and @BeforeClass differences 3 60
jar file executable 12 52
factorial example 4 41
jdbc error in jsp application 20 47
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question