Determining from Where a Class Was Loaded
// Get the location of this class
Class cls = this.getClass();
ProtectionDomain pDomain = cls.getProtectionDomain();
CodeSource cSource = pDomain.getCodeSource();
URL loc = cSource.getLocation(); // file:/c:/almanac14/examples/
> java -verbose MyApp
[Opened c:\jdk1.4\jre\lib\rt.jar]
[Opened c:\jdk1.4\jre\lib\sunrsasign.jar]
[Opened c:\jdk1.4\jre\lib\jsse.jar]
[Opened c:\jdk1.4\jre\lib\jce.jar]
[Opened c:\jdk1.4\jre\lib\charsets.jar]
[Loaded java.lang.Object from c:\jdk1.4\jre\lib\rt.jar]
[Loaded java.io.Serializable from c:\jdk1.4\jre\lib\rt.jar]
[Loaded java.lang.Comparable from c:\jdk1.4\jre\lib\rt.jar]
[Loaded java.lang.CharSequence from c:\jdk1.4\jre\lib\rt.jar]
[Loaded java.lang.String from c:\jdk1.4\jre\lib\rt.jar]
[Loaded java.lang.Class from c:\jdk1.4\jre\lib\rt.jar]
[Loaded java.lang.Cloneable from c:\jdk1.4\jre\lib\rt.jar]
[Loaded java.lang.ClassLoader from c:\jdk1.4\jre\lib\rt.jar]
[Loaded java.lang.System from c:\jdk1.4\jre\lib\rt.jar]
[Loaded java.lang.Throwable from c:\jdk1.4\jre\lib\rt.jar]
Very Nice article. I juste wanted to know, in case of multi threaded application, where every thread is responsible for creating and destroying Object of Class A.
If the threads are running one after another with no overlapping period and may have some deplay in there execution, how many times, Class A will be loaded.