class loader
类装入器
2025-09-06 19:04 浏览次数 6
类装入器
the method now delegates to its parent class loader before attempting to find the class itself.
方法现在在试图自己找到类之前,先委托给自己的双亲类装入器。
a modified class loader uses template files that look almost exactly like ordinary class files except for 「holes」 in the constant pool that are filled in at load time for each instantiation class.
修改的类装入器使用看上去几乎与普通类文件完全一样的模板文件,不同的是这个模板文件在常量池中有一些「洞」,在装入时为每个实例化类填充这些「洞」。
the class loader plays an important role in linking a native call to its appropriate native definition.
在把本机调用链接到对应的本机定义时,类装入器扮演着重要角色。
to avoid this problem, any classes that are to be serialized should be loaded by a class loader that does not need to be garbage collected -- by the system class loader, for example.
为了避免这个问题,凡是要进行序列化的类,都应当由不需要被垃圾收集的类装入器装入 ——例如由系统类装入器装入。
this article, the final installment in this four-part series, examines class loader deadlocks and constraint violations.
本文是本系列中的四篇文章的最后一篇,它研究了类装入器死锁和约束违反。
but how can that work if the class loader looks for existing class files for each class it loads?
但是,如果类装入器为它所装入的每个类查找现有类文件,那么它会如何工作呢?
while the simplest way to avoid class loader constraint violations is to only have one copy of a class in the system, it is sometimes necessary to have multiple versions.
虽然避免类装入器约束违反的最简单方法是在系统中只有类的一个副本,但有时拥有多个版本也是有必要的。
each j2ee application loaded by the framework needs to have a separate class loader to prevent classes in one application from interfering with other applications.
该框架装入的每个j2ee应用程序都需要拥有一个独立的类装入器以防止一个应用程序中的类干扰其它应用程序。
because all four conditions hold, this situation results in a class loader constraint violation.
因为四个条件全部成立,所以这种情况会导致类装入器约束违反。
a class loader deadlock occurs when two threads each own a lock on two different class loaders, and both threads are waiting for the lock owned by the other thread.
当两个线程在两个不同的类装入器上都拥有各自的锁,同时又都等候对方拥有的锁的时候,就会发生类装入器死锁。
among other things, the collector examines the class loader data structures to determine which classes are live -- that is, are not garbage collectable.
在众多的事情当中,收集器检查类装入器的数据结构,来判断哪个类是活动的 —— 也就是说,不应当被当作垃圾收集的。
these methods let the framework set the class loader to be used for each application while running code from that application.
这些方法允许该框架设置类装入器,使得在运行每个应用程序中的代码时可以将类装入器用于该应用程序。
it also indicates which class loader loads a given class and where it loads it from.
它还可以指出指定类是由哪个类装入器装入的、从哪里装入的。
for example, a class loader could first load a class explicitly and then load all of its referenced classes implicitly.
例如,类装入器可能先显式地装入一个类,然后再隐式地装入它引用的所有类。
in this prototype implementation, we have employed a modified class loader to support polymorphic recursion.
在该原型实现中,我们使用了一个修改的类装入器来支持多态递归。
though dereferencing a user-defined class loader seems like a way to ensure that the classes are garbage collected, this is not actually the case.
虽然取消对用户定义的类装入器的引用看起来像是一种确保类被垃圾收集的方法,但实际并不是这回事。
by default, this class loader is the parent of any class loader created by the user.
默认情况下,这个类装入器是用户创建的任何类装入器的父类。
it uses the system class loader to achieve this.
它使用系统类装载程序来达到这个目的。
this particular class loader has some special features.
这个特殊的类装入器有一些专门的特性。
in other words, when two class loaders load different classes (that is, different bytecodes) with the same name, class loader constraints guarantee that there will be no type mismatch between them.
换句话说,当两个类装入器用相同的名称装入不同的类时(也就是不同的字节码),类装入器约束保证了它们之间不会有类型不匹配。
this is because b is not in the classpath of the system class loader or its parent or ancestor class loaders.
这是因为b不在系统类装入器或者它的双亲或祖先类装入器的类路径中。
it also shows class loader information -- again, this is simple because the application is so simple.
它还展示了类加载器信息 ——再说一遍,这很简单,因为应用程序太简单了。