Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scenario when one may be requiring custom class loader?

Tags:

java

jvm

I am looking for a simple scenario when can be requirement to create a custom class loader?

Apart from that, just wanted to confirm that Does even bootstrap and application class loader extends java.lang.ClassLoader internally?

like image 823
M Sach Avatar asked Sep 20 '11 18:09

M Sach


1 Answers

In short, it can be used to add new code or to change existing code on the fly. Here's a more detailed explanation from this URL.

Why write a custom class loader?

The three main reasons for wanting to create a custom class loader are:

  • To allow class loading from alternative repositories.

    This is the most common case, in which an application developer might want to load classes from other locations, for example, over a network connection.

  • To partition user code.

    This case is less frequently used by application developers, but widely used in servlet engines.

  • To allow the unloading of classes.

    This case is useful if the application creates large numbers of classes that are used for only a finite period. Because a class loader maintains a cache of the classes that it has loaded, these classes cannot be unloaded until the class loader itself has been dereferenced. For this reason, system and extension classes are never unloaded, but application classes can be unloaded when their classloader is.

like image 168
RHT Avatar answered Nov 01 '22 16:11

RHT