ClassLoader获取的两种方式
来源:互联网 发布:ubuntu 启动 黑屏 u盘 编辑:程序博客网 时间:2024/06/16 03:48
其一java 1.2以及之后:
Method method = Thread.class.getMethod("getContextClassLoader", null);ClassLoader cl = (ClassLoader) method.invoke(Thread.currentThread(), null);
通用:ClassLoader cl = className.class.getClassLoader();
log4j中的loader#getTCL源码实例:
/**
* Get the Thread Context Loader which is a JDK 1.2 feature. If we are
* running under JDK 1.1 or anything else goes wrong the method returns
* <code>null<code>.
*
* */
private static ClassLoader getTCL()
throws IllegalAccessException, InvocationTargetException
{
// Are we running on a JDK 1.2 or later system?
Method method = null;
try
{
method = Thread.class.getMethod("getContextClassLoader", null);
}
catch (NoSuchMethodException e)
{
// We are running on JDK 1.1
return null;
}
return (ClassLoader)method.invoke(Thread.currentThread(), null);
}
- ClassLoader获取的两种方式
- ClassLoader获取的方式
- classLoader获取的几种方式
- android获取Bitmap的两种方式
- ajax获取数据的两种方式
- 两种获取connectionString的方式
- struts2获取请求的两种方式
- jfreechart获取图片的两种方式
- 获取文件属性的两种方式---ACL
- 获取进程信息的两种方式
- javaSE--随机数的两种获取方式
- 获取数据库连接的两种实现方式
- 获取android 屏幕分辨率的两种方式
- 获取servletContext对象的两种方式
- android获取屏幕分辨率的两种方式
- hibernate获取session的两种方式
- 获取根节点的两种方式
- C获取时间的两种方式
- 笔试or面试忘记or不懂的东西
- 设计模式:几种常见的设计模式
- TopCoder SRM 589 Div2 第2题
- 黑马程序员_java面向对象(二) 继承
- Android屏幕解锁图案破解
- ClassLoader获取的两种方式
- 化解提笔忘字依赖技术手段——汉字拼形
- 【热门主题: 高清雪景桌面壁纸】
- java 伪装成浏览器向 网站发起请求
- linux 定时备份数据资料
- android 中 系统日期时间的获取
- 函数指针高阶运用(C++函数指针)
- SQL面试题大全
- <iOS>other linker flags