Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A common use of classloaders is to isolate a JAR. If you have an application which uses plugins (<a href="http://www.eclipse.org/" rel="noreferrer">Eclipse</a>, <a href="http://maven.apache.org/" rel="noreferrer">Maven 2</a>), then you can have this situation: Plugin X needs jar A with version 1.0 while plugin Y need the same jar but version 2.0. X does not run with version 2.0, though.</p> <p>If you have classloaders, you can create partitions of classes (think of isolated islands connected by thin bridges; the bridges are the classloaders). This way, the classloaders can control what each plugin can see.</p> <p>When plugin X instantiates a class Foo, which has static fields, this is no problem and there won't be a mixup with the "same" class in plugin Y because each classloader will in fact create its own instance of the class Foo. You then have two classes in memory, where <code>cl1.getName().equals(cl2.getName())</code> is <code>true</code> but <code>cl1.equals(cl2)</code> is not. This means that instances of cl1 are not assignment compatible to instances of cl2. This can lead to strange <code>ClassCastExceptions</code> which say that <code>org.project.Foo</code> can't be assigned to <code>org.project.Foo</code>.</p> <p>Just like with remote islands, the two classes are not aware that the other one exists. Think of human clones which are born and then raised on different islands. From the point of view of the VM, there is no problem because instances of the type Class are handled like any other object: There can be several of them. That you think that some of them are "the same" doesn't matter to the VM.</p> <p>Another use for this pattern is that you can get rid of classes loaded this way: Just make sure that no one has a pointer to any object created from classes loaded from a classloader and then forget about the classloader, too. On the next run of the <a href="http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)" rel="noreferrer">GC</a>, all classes loaded by this classloader are removed from memory. This allows you to "reload" your application without having to restart the whole VM.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload