classloader总结

本文探讨了在项目中遇到的ClassCastException问题及其解决方案。特别是在使用自定义类加载器时,如何保持线程上下文类加载器与当前类加载器一致,避免因类加载机制导致的异常。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目时需要对外提供一些服务接口,写了接口及其实现发现报castClassException,当时newInstance时采用
Thread.currentContext.getClassLoader的形式,分析了一下发现平台采用了自己的classloader

1.java的classloader采用双亲委托的机制
2.当前类加载器和线程上下文的区别是,当前类加载器在加载caller类时已经确定,但thread's context classloader is modifiable
3.thread's classloader can break through the parent delegation mechanism of classloader
4.it is should keep the thread's classloader same as current class classloader
5.the default form of class.forname isn't recommend,because of exception of initializing static field if the classloader is not
destroied
6.banq comment about adoption thread's  classloader is not correctly

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值