当前位置:网站首页>Jvm: thread context classloader
Jvm: thread context classloader
2022-06-12 01:09:00 【amadeus_ liu2】
One 、 When the context class loader is not actively set , The thread context class loader is the application class loader (AppClassLoader)
1. introduce MySQL package
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.30</version>
</dependency>
2. test ThreadContextClassLoader
package cn.edu.tju;
import java.sql.Driver;
import java.util.Iterator;
import java.util.ServiceLoader;
public class ThreadContextClassLoaderTest {
public static void main(String[] args) {
ServiceLoader<Driver> serviceLoader=ServiceLoader.load(Driver.class);
Iterator<Driver> iterator = serviceLoader.iterator();
while(iterator.hasNext()){
System.out.println(iterator.next().getClass());
}
}
}
3. Operation output :
4. Result analysis : Because there are no settings ThreadContexClassLoader, So the main thread ThreadContextClassLoader by AppClassLoader, It can be loaded from the application's classpath MySQL Of the two Driver class .
5. Modify main class :
package cn.edu.tju;
import java.sql.Driver;
import java.util.Iterator;
import java.util.ServiceLoader;
public class ThreadContextClassLoaderTest {
public static void main(String[] args) {
Thread.currentThread().setContextClassLoader(SpiTest.class.getClassLoader().getParent());
ServiceLoader<Driver> serviceLoader=ServiceLoader.load(Driver.class);
Iterator<Driver> iterator = serviceLoader.iterator();
while(iterator.hasNext()){
System.out.println(iterator.next().getClass());
}
}
}
Change the context class loader of the thread to AppClassLoader Of parent namely ExtClassLoader, Will not be able to load... Under the classpath MySQL Of Driver class , therefore , The program runs without output
边栏推荐
- 一文get,最容易碰上的接口自动化测试问题汇总
- Global and Chinese maleic anhydride polypropylene industry investment analysis and prospect trend forecast report 2022 Edition
- [roe] (2) roe agreement
- Article 5: Design of multi-functional intelligent trunk following control system | undergraduate graduation design - [learning of controller arduino+stm32]
- Online Fox game server - room configuration wizard - component attribute and basic configuration assignment
- 2022 edition of global and Chinese high purity silicon carbide powder operation research and investment strategy analysis report
- Matlab 基础04 - 冒号Colon operator “:”的使用和复杂应用详析
- A knowledge map (super dry goods, recommended collection!)
- Lambda中间操作skip
- Matlab 基础应用02 wind 股票数据介绍和使用案例:
猜你喜欢

Weekly CTF 第一周:神奇的磁带

Data visualization big screen - big screen cloud minimalist user manual

给你一个项目,你将如何开展性能测试工作?

网狐游戏服务器-房间配置向导-组件属性与基本配置赋值

基于.NetCore开发博客项目 StarBlog - (11) 实现访问统计
![[roe] (2) roe agreement](/img/5a/598da9b140216df046698766de41bb.png)
[roe] (2) roe agreement

Streaming data warehouse storage: requirements and architecture

System. Commandline option

flowable 工作流

Zhongchuang patents | China has 18000 necessary patents for 5g standards, respects intellectual property rights and jointly builds a strong intellectual property country
随机推荐
Lambda中间操作flatMap
Nat. Comm. | 超算+AI: 为天然产物生物合成路线规划提供导航
Practice of Flink CDC + Hudi massive data entering the lake in SF
Recurrent+Transformer 视频恢复领域的‘德艺双馨’
Analysis report on operation trends and development strategies of global and Chinese plastic adhesive industry 2022-2028
Investment analysis and prospect Trend Research Report of global and Chinese cyclopentanyl chloride industry 2022-2028
LabVIEW Arduino electronic weighing system (project Part-1)
Ms-hgat: information diffusion prediction based on memory enhanced sequence hypergraph attention network
Kill session? This cross domain authentication solution is really elegant
打造Flutter高性能富文本编辑器——渲染篇
Lambda中间操作filter
'virtue and art' in the field of recurrent+transformer video recovery
C dynamically calls the static library generated by go
2022 edition of global and Chinese on silicon liquid crystal market supply and demand research and prospect Trend Forecast Report
Creating a flutter high performance rich text editor - rendering
[signalr complete series] Implementation of signalr packet communication in net6
jvm: 线程上下文类加载器(TheadContextClassLoader)
王希廷博士:从知识图谱和自然语言生成的角度认识可解释推荐
[path of system analysts] summary of real problems of system analysts over the years
Lambda intermediate operation flatmap