日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

JavaSE之ClassLoader

發布時間:2025/3/18 java 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JavaSE之ClassLoader 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

A class loader is an object that is responsible for loading classes.

類加載器是負責加載class的一種對象.

The class ClassLoader is an abstract class.

類ClassLoader是一個抽象類.

Given the?binary name?of a class, a class loader should attempt to locate or generate data that constitutes a definition for the class.

對于給定的一個類的完全限定名, 一個類加載器應該試著去定位或者生成”這個類的定義數據”.

A typical strategy is to transform the name into a file name and then read a "class file" of that name from a file system.

一個典型的策略是將這個名字轉換成一個文件的名字, 然后從文件系統中讀取這個名字的class文件.

?

Every Class object contains a reference to the ClassLoader that defined it.

每一個Class對象都包含一個指向加載它的ClassLoader的引用.

?

Class objects for array classes are not created by class loaders, but are created automatically as required by the Java runtime.

數組類的Class對象并不是類加載器創建的, 而是根據需要自動地被JVM創建出來的.

The class loader for an array class, as returned by Class.getClassLoader() is the same as the class loader for its element type; if the element type is a primitive type, then the array class has no class loader.

數組類通過Class.getClassLoader()返回的類加載器是這個數組包含的元素類型的類加載器; 如果元素類型是原始類型的話, 那這個數組就沒有類加載器.

?

Applications implement subclasses of ClassLoader in order to extend the manner in which the Java virtual machine dynamically loads classes.

實現了ClassLoader的子類的應用是為了擴展JVM動態加載類的方式.

?

Class loaders may typically be used by security managers to indicate security domains.

類加載器可能被典型地應用在security manager中, 用來表明安全的區域.

?

The?ClassLoader?class uses a delegation model to search for classes and resources.

ClassLoader類使用委托模型來搜索類文件和各種資源文件.

Each instance of?ClassLoader?has an associated parent class loader.

每一個ClassLoader的實例都關聯著parent的類加載器.

When requested to find a class or resource, a?ClassLoader?instance will delegate the search for the class or resource to its parent class loader before attempting to find the class or resource itself.

當被請求查找一個類文件或資源文件時, 一個ClassLoader實例將會委托這個查找給它的父親類加載器, 只有父親類加載器沒有找到這個類文件或資源文件時, 才會自己去查找.

The virtual machine's built-in class loader, called the "bootstrap class loader", does not itself have a parent but may serve as the parent of a?ClassLoader?instance.

JVM內置的類加載器, 叫做”bootstrap class loader”, 它自己并沒有一個父親類加載器, 但是可能會作為其他類加載器的父親.

?

Class loaders that support concurrent loading of classes are known as?parallel capable?class loaders and are required to register themselves at their class initialization time by invoking the?ClassLoader.registerAsParallelCapable?method.

支持并行加載的類加載器被稱為"parallel capable類加載器”, 它們被要求在類的初始化的時候通過調用”ClassLoader.registerAsParallelCapable”方法來注冊.

Note that the?ClassLoader?class is registered as parallel capable by default. However, its subclasses still need to register themselves if they are parallel capable.

注意:?ClassLoader類默認已經被注冊為”parallel capable”, 然而它的子類仍然需要注冊

In environments in which the delegation model is not strictly hierarchical, class loaders need to be parallel capable, otherwise class loading can lead to deadlocks because the loader lock is held for the duration of the class loading process (see?loadClass?methods).

在一些環境中, 委托模型并不是嚴格地繼承性的, 因為類加載器需要是并行的. 否則的話, 類在加載過程中可能會導致死鎖, 由于loader lock在類加載的過程中被保持了. (參見loadClass方法.)

?

Normally, the Java virtual machine loads classes from the local file system in a platform-dependent manner.?

正常來說, JVM以一種系統獨立的方式從本地文件系統加載class文件.

For example, on UNIX systems, the virtual machine loads classes from the directory defined by the?CLASSPATH?environment variable.

例如 ,在unix系統上, JVM從”CLASSPATH"這個環境變量定義的路徑中加載class文件.


However, some classes may not originate from a file; they may originate from other sources, such as the network, or they could be constructed by an application.

然而, 一些class可能不是來源于文件, 它們可能出自于其他的來源, 比如網絡或者被一個應用構建出來.

The method?defineClass?converts an array of bytes into an instance of class?Class. Instances of this newly defined class can be created using?Class.newInstance.

defineClass方法將一個字節數組轉換為一個Class類的實例. 這個新定義的Class類的實例可以通過方法Class.newInstance創建.

?

The methods and constructors of objects created by a class loader may reference other classes.

通過類加載器創建的方法和構造器可能引用其他的類.

To determine the class(es) referred to, the Java virtual machine invokes the?loadClass?method of the class loader that originally created the class.

為了判斷引用的類型, JVM調用最初創建這個類的類加載器的loadClass方法

?

For example, an application could create a network class loader to download class files from a server. Sample code might look like:

ClassLoader loader?= new NetworkClassLoader(host,?port); Object main?= loader.loadClass("Main", true).newInstance(); .?.?.

The network class loader subclass must define the methods?findClass?and?loadClassData?to load a class from the network. Once it has downloaded the bytes that make up the class, it should use the method?defineClass?to create a class instance. A sample implementation is:

class NetworkClassLoader extends ClassLoader { String host; int port; public Class findClass(String name) { byte[] b = loadClassData(name); return defineClass(name, b, 0, b.length); } private byte[] loadClassData(String name) { // load the class data from the connection ? .?.?. } } ?

Binary names

Any class name provided as a?String?parameter to methods in?ClassLoader?must be a binary name as defined by?The Java? Language Specification.

Examples of valid class names include:

"java.lang.String" "javax.swing.JSpinner$DefaultEditor" "java.security.KeyStore$Builder$FileBuilder$1" "java.net.URLClassLoader$3$1"

轉載于:https://www.cnblogs.com/wanquanyou/p/7261953.html

總結

以上是生活随笔為你收集整理的JavaSE之ClassLoader的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。