可能需要自定义类加载器的场景?
我正在寻找一个简单的场景,何时需要创建自定义类加载器?
除此之外,只是想确认引导程序和应用程序类加载器是否在内部扩展了 java.lang.ClassLoader ?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简而言之,它可用于添加新代码或动态更改现有代码。这里有一个更详细的解释 网址。
为什么要编写自定义类加载器?
想要创建自定义类加载器的三个主要原因是:
允许从替代存储库加载类。
这是最常见的情况,应用程序开发人员可能希望从其他位置加载类,例如通过网络连接。
对用户代码进行分区。
这种情况较少被应用程序开发人员使用,但广泛用于 servlet 引擎。
允许卸载类。
如果应用程序创建大量仅在有限时间内使用的类,则这种情况非常有用。由于类加载器维护已加载的类的缓存,因此在取消引用类加载器本身之前,无法卸载这些类。因此,系统类和扩展类永远不会被卸载,但应用程序类可以在其类加载器卸载时被卸载。
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.