Custom Class Loader有什么用? [英] What is the use of Custom Class Loader

查看:201
本文介绍了Custom Class Loader有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我遇到了java自定义类加载器api。我在这里找到了一个用途, kamranzafar的博客
我对类加载器概念有点新意。任何人都可以详细解释,我们可能需要它的不同场景是什么,或者我们应该使用它?

Recently I came accross the java custom class loader api. I found one use over here, kamranzafar's blog I am a bit new to the class loader concept. Can any one explain in detail, what are the different scenarios where we may need it or we should use it?

推荐答案

自定义类加载器在由多个模块/应用程序组成的较大体系结构中很有用。以下是自定义类加载器的优点:

Custom class loaders are useful in larger architectures consisting of several module/applications. Here are the advantages of the custom class loader:


  • 提供模块化架构允许定义多个类加载器允许模块化

  • 避免冲突清楚地在类加载器中定义类的范围。

  • 支持版本控制支持不同模块在同一个VM中的不同版本的类。

  • 更好的内存管理可以删除未使用的模块,卸载该模块使用的类,从而清理内存。

  • 从任何地方加载类可以从任何地方加载类, for ex,数据库,网络,甚至可以动态定义

  • 动态添加资源或类以上所有功能允许您动态添加类或资源。

  • 运行时重新加载修改的类允许您通过为实际的类加载器创建子类加载器来重新加载类或类运行时,其中包含修改过的类。

  • Provides Modular architecture Allows to define multiple class loader allowing modular architecture.
  • Avoiding conflicts Clearly defines the scope of the class to within the class loader.
  • Support Versioning Supports different versions of class within same VM for different modules.
  • Better Memory Management Unused modules can be removed which unloads the classes used by that module, which cleans up memory.
  • Load classes from anywhere Classes can be loaded from anywhere, for ex, Database, Networks, or even define it on the fly.
  • Add resources or classes dynamically All the above features allows you add classes or resources dynamically.
  • Runtime Reloading Modified Classes Allows you to reload a class or classes runtime by creating a child class loader to the actual class loader, which contains the modified classes.

这篇关于Custom Class Loader有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆