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.mzph.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的上位机模板出来,以后的项目就要彻底…