Java虚拟机类型卸载和类型更新解析

15 篇文章 0 订阅

Java虚拟机类型卸载和类型更新解析

 

 

首先看一下,关于java虚拟机规范中时如何阐述类型卸载(unloading)的:

 

A class or interface may be unloaded if and only if its class loader is unreachable. The bootstrap class loader is always reachable; as a result, system classes may never be unloaded.

 

Java虚拟机规范中关于类型卸载的内容就这么简单两句话,大致意思就是:只有当加载该类型的类加载器实例(非类加载器类型)为unreachable状态时,当前被加载的类型才被卸载.启动类加载器实例永远为reachable状态,由启动类加载器加载的类型可能永远不会被卸载.

 

我们再看一下Java语言规范提供的关于类型卸载的更详细的信息(部分摘录):

 

//摘自JLS 12.7 Unloading of Classes and Interfaces

 

1、An implementation of the Java programming language may unload classes.

 

2、Class unloading is an optimization that helps reduce memory use. Obviously,the semantics of a program should not depend on whether and how a system chooses to implement an optimization such as class unloading.

 

3、Consequently,whether a class or interface has been unloaded or not should be transparent to a program

 

通过以上我们可以得出结论: 类型卸载(unloading)仅仅是作为一种减少内存使用的性能优化措施存在的,具体和虚拟机实现有关,对开发者来说是透明的.

 

纵观java语言规范及其相关的API规范,找不到显示类型卸载(unloading)的接口, 换句话说:

 

1、一个已经加载的类型被卸载的几率很小至少被卸载的时间是不确定的

 

2、一个被特定类加载器实例加载的类型运行时可以认为是无法被更新的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值