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

歡迎訪問 生活随笔!

生活随笔

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

java

Java线程类void setContextClassLoader(ClassLoader loader)方法,带示例

發布時間:2023/12/1 java 56 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java线程类void setContextClassLoader(ClassLoader loader)方法,带示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

線程類void setContextClassLoader(ClassLoader loader) (Thread Class void setContextClassLoader(ClassLoader loader))

  • This method is available in package java.lang.Thread.setContextClassLoader(ClassLoader loader).

    軟件包java.lang.Thread.setContextClassLoader(ClassLoader loader)中提供了此方法。

  • This method is used to sets the context ClassLoader for this(Current)Thread.

    此方法用于為此(當前)線程設置上下文ClassLoader。

  • The context ClassLoader can be set at the time of thread creation by which thread creator could access the thread and provide appropriate the class loader to code run in the program at the time of class loading.

    可以在創建線程時設置上下文ClassLoader,通過該上下文,線程創建者可以訪問線程并提供適當的類加載器,以在類加載時在程序中運行代碼。

  • This method is not static so this method is accessible with Thread class object it is not accessible with the class name.

    此方法不是靜態的,因此該方法可通過Thread類對象訪問,而無法通過類名稱訪問。

  • The return type of this method is void so it does not return anything.

    此方法的返回類型為void,因此它不返回任何內容。

  • This method raises an exception (SecurityException) if this thread could not set the context ClassLoader.

    如果此線程無法設置上下文ClassLoader,則此方法引發異常(SecurityException)。

Syntax:

句法:

void setContextClassLoader(ClassLoader loader){}

Parameter(s):

參數:

We pass only one object as a parameter in the method of the Thread and the parameter is the context ClassLoader for this thread.

我們僅在Thread方法中傳遞一個對象作為參數,并且該參數是該線程的上下文ClassLoader。

Return value:

返回值:

The return type of this method is void, it does not return anything.

此方法的返回類型為void ,它不返回任何內容。

Java程序演示setContextClassLoader()方法的示例 (Java program to demonstrate example of setContextClassLoader() method)

/* We will use Thread class methods so we are importing the package but it is not mandate because it is imported by default */import java.lang.Thread;class SetContextClassLoader extends Thread {// Override run() of Thread classpublic void run() {//Display a message for the end user System.out.println("The name of this thread is " + " " + Thread.currentThread().getName());}public static void main(String[] args) {// Creating an object of SetContextClassLoader classSetContextClassLoader ccl = new SetContextClassLoader();// Creating an object of Thread classThread th = new Thread(ccl);// Thread class start() method will call and it will ultimately th.start();// getContextClassLoader() will return context ClassLoader // and create a reference of ClassLoaderClassLoader cl = th.getContextClassLoader();// By using setContextClassLoader(ClassLoader cl) sets // the context ClassLoader for this thread thth.setContextClassLoader(cl);System.out.println("The Context ClassLoader for this thread th is = " + cl);System.out.println("The Parent of the ClassLoader is = " + cl.getParent());System.out.println("The Class of the ClassLoader is = " + cl.getClass());} }

Output

輸出量

E:\Programs>javac SetContextClassLoader.javaE:\Programs>java SetContextClassLoader The Context ClassLoader for this thread th is = [email?protected]The name of this thread is Thread-1The Parent of the ClassLoader is = [email?protected]The Class of the ClassLoader is = class sun.misc.Launcher$AppClassLoader

翻譯自: https://www.includehelp.com/java/thread-class-void-setcontextclassloader-classloader-loader-method-with-example.aspx

總結

以上是生活随笔為你收集整理的Java线程类void setContextClassLoader(ClassLoader loader)方法,带示例的全部內容,希望文章能夠幫你解決所遇到的問題。

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