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 class
public 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 class
SetContextClassLoader ccl = new SetContextClassLoader();
// Creating an object of Thread class
Thread 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 ClassLoader
ClassLoader cl = th.getContextClassLoader();
// By using setContextClassLoader(ClassLoader cl) sets 
// the context ClassLoader for this thread th
th.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.java
E:\Programs>java SetContextClassLoader
The Context ClassLoader for this thread th is = [email?protected]
The name of this thread is  Thread-1
The 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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/376957.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/376957.shtml
英文地址,請注明出處:http://en.pswp.cn/news/376957.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

JPA概要

本文最新版已更新至:http://thinkinside.tk/2012/12/30/JPA.html JPA定義了Java ORM及實體操作API的標準。本文摘錄了JPA的一些關鍵信息以備查閱。 如果有hibernate的基礎,通過本文也可以快速掌握JPA的基本概念及使用。 Table of Contents 1 JPA概述2 實…

如何配置能讓fiddler抓去https的請求?

1、打開fiddler,>>Tools>>Fiddler Options, 打開如圖所示的HTTPS配置項:點擊Export Rppt Certifica to Desktop :桌面上多了一個證書:下面就是將證書導入:點擊開始-運行,輸入:mmc,…

Redis對象的refcount與lru屬性(內存回收、對象共享、空轉時長)

本筆記參考《Redis設計與實現》 P84~P88 內存回收 Redis在對象系統中使用reference counting技術實現了內存回收機制。程序可以通過跟蹤對象的引用計數信息,在適當的時候自動釋放對象并進行內存回收。 typedef struct redisObject {// ...// 引用計數int refcoun…

【閑聊】Baidu Map,excellent !!!Diaoyv island is China 's

【釣魚島】釣魚島是中國的!Diaoyu Islands are Chinas! 釣魚島は中國のアール! ————————————youngLaker轉載于:https://www.cnblogs.com/younglaker/archive/2012/12/31/2840190.html

08:vigenère密碼_密碼技術:Vigenére密碼,Playfair密碼,Hill密碼

08:vigenre密碼1)Vigenre密碼 (1) Vigenre Cipher) This technique is an example of Polyalphabetic Substitution technique which uses 26 Caesar ciphers make up the mono-alphabetic substitution rules which follow a count shifting mechanism from 0 to 25. That is,…

Redis的RDB文件與AOF文件

本筆記參考《Redis設計與實現》 P118 ~ P150 RDB文件 1、RDB文件用于保存和還原Redis服務器所有數據庫中的所有鍵值對數據 2、SAVE命令由服務器進程直接執行保存操作,該命令會阻塞服務器 3、BGSAVE命令由子進程執行保存操作,不會阻塞服務器 注意此時服…

eclipse擴容

eclipse擴容 -vmD:/jdk-6u17-windows-i586/jdk1.6.0_17/bin/javaw.exe-startupplugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar-nlen_US--launcher.libraryplugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.200.v20120913-144807-productorg.eclipse…

node oauth2驗證_如何設置和使用護照OAuth Facebook身份驗證(第2部分)| Node.js

node oauth2驗證In my last article (How to set up and use passport OAuth Facebook Authentication (Section 1) | Node.js), we looked at another form of authentication called the OAuth authentication which involves sign in or signup using social media. 在我的上…

Python and Microsoft Word

國外網站看到的文章:Accessing Microsoft Word with Python follows the same syntax that we used for Excel. Let’s take a quick look at how to access Word.from time import sleep import win32com.client as win32RANGE range(3, 8)def word():word win32…

東哥讀書小記 之 《一個廣告人的自白》

掰著指頭一算,端午假期確實完成不少事情,過的太尼瑪充實鳥:去健身房2小時,且老夫的平板支撐終于能堅持超過1分鐘,普大喜奔有木有;給合租的室友買蛋糕過了個生日;去 去哪兒 參加W3ctech的技術交流…

Redis的文件事件與時間事件處理

目錄文件事件處理事件類型客戶端和服務端的通信過程時間事件處理執行器執行周期性事件作用事件的調度與執行文件事件處理 Redis基于Reactor模式開發了文件事件處理器。文件事件處理器以單線程方式運行,通過IO多路復用程序監聽多個套接字,實現了高性能網…

fisher-yates_使用Fisher-Yates隨機播放算法以O(n)時間隨機播放給定數組

fisher-yatesExample: 例: Say the input array is [1, 2 3, 4, 5 6, 7]After reshuffling it can be anything like[4, 3, 7, 2, 1, 5, 1]Our goal is that the reshuffling should be as random as possible. 我們的目標是,改組應盡可能地隨機。 The…

[分享]一些在 WPF/Silverlight 中應用 MVVM 模式時可能會有點用途的代碼

想來這個博客也已經有很久沒更新過了,新年新氣象,現在就開始寫新內容吧。 最初的起因 在最近的幾個月中我做的開發總是要跟 XAML 打交道,也就是 WPF 啊,Silverlight 啊,WF 啊這些。 在進行 WPF 和 Silverlight 開發的…

手機調用系統的拍照和裁剪功能,假設界面有輸入框EditText,在一些手機會出現點擊EditText會彈出輸入法,卻不能輸入的情況。...

1、拍照裁剪后 點擊EditText會彈出輸入法,卻不能輸入。可是點擊點一EdtiText就能夠輸入了,所以我就寫了一個看不見的EdtiText,切換焦點,這樣就攻克了這個奇怪的這問題,應該是android內部的問題。 這是網絡一個牛人留下…

Redis一個命令請求從發送到完成的步驟以及初始化服務器步驟

一個命令請求從發送到完成的步驟 如下: 1、客戶端將命令請求發送給服務器 當用戶在客戶端中鍵入一個命令請求時,客戶端會將這個命令請求轉換成協議格式,然后通過連接到服務器的套接字,將協議格式的命令請求發送給服務器。 2、服…

c打印行號和函數_使用C中的函數名稱,行號從任何函數打印錯誤消息

c打印行號和函數Sometimes, it is necessary to print some message on logic failure or anytime with the function name and line number, so that program can be debugged and fixed the issue. 有時,有必要在邏輯故障時或在任何時候使用功能名稱和行??號打印…

Linux SPI框架

水平有限,描述不當之處還請指出,轉載請注明出處http://blog.csdn.net/vanbreaker/article/details/7733476 Linux的SPI子系統采用主機驅動和外設驅動分離的思想,首先主機SPI控制器是一種平臺設備,因此它以platform的方式注冊進內…

dbms標識符無效_DBMS中的嵌套查詢,相關的嵌套查詢和集合比較運算符

dbms標識符無效嵌套查詢 (Nested Queries) A query embedded in a query. This type of relation is termed as Nested Query and the Embedded Query is termed as a subquery. 查詢中嵌入的查詢。 這種類型的關系稱為嵌套查詢,而嵌入式查詢稱為子查詢。 For exam…

重構——解決過長參數列表(long parameter list)

目錄1、Replace Param with Query2、Preserve Whole Object3、Introduce Param Object4、Remove Flag Argument5、Combine Functions into ClassReference當我們需要在超長函數中提煉子函數時,如果函數內有大量的參數和臨時變量,這將會對函數的提煉形成很…

C# 點點滴滴: out和ref

用c#很長一段時間了,不過基本是啥都不會,當C用的,作為寫單片機的,還是真心覺得C比較親切,呵呵。 不過總是要進步啊,慢慢積累唄,這次是寫一個CAN的上位機模板出來,以后的項目就要徹底…