当前位置: 首页 > news >正文

老板说做个网站我要怎么做公司网页怎么做

老板说做个网站我要怎么做,公司网页怎么做,网软志成企业网站管理系统,手机app与网站链接类加载器ClassLoad-jdk1.8 1. 类加载器的作用2. 类加载器的种类(JDK8)3. jvm内置类加载器如何搜索加载类--双亲委派模型4. 如何打破双亲委派模型--自定义类加载器5. 自定义一个类加载器5.1 为什么需要自定义类加载器5.2 自定义一个类加载器 6. java代码加…

类加载器ClassLoad-jdk1.8

    • 1. 类加载器的作用
    • 2. 类加载器的种类(JDK8)
    • 3. jvm内置类加载器如何搜索加载类--双亲委派模型
    • 4. 如何打破双亲委派模型--自定义类加载器
    • 5. 自定义一个类加载器
      • 5.1 为什么需要自定义类加载器
      • 5.2 自定义一个类加载器
    • 6. java代码加载类的方式
    • 7. jdk9 的类加载器结构
    • 参考文章

1. 类加载器的作用

  • 顾名思义,它是用来加载 Class 的。它负责将 Class 的字节码形式转换成内存形式的 Class 对象。
  • 延迟加载。JVM 运行并不是一次性加载所需要的全部类的,它是按需加载,也就是延迟加载。程序在运行的过程中会逐渐遇到很多不认识的新类,这时候就会调用 ClassLoader 来加载这些类。加载完成后就会将 Class 对象存在 ClassLoader 里面,下次就不需要重新加载了。
  • 传递性。程序在运行过程中,遇到了一个未知的类,它会选择哪个 ClassLoader 来加载它呢?虚拟机的策略是使用调用者 Class 对象的 ClassLoader 来加载当前未知的类。何为调用者 Class 对象?就是在遇到这个未知的类时,虚拟机肯定正在运行一个方法调用(静态方法或者实例方法),这个方法挂在哪个类上面,那这个类就是调用者 Class 对象。前面我们提到每个 Class 对象里面都有一个 classLoader 属性记录了当前的类是由谁来加载的。

2. 类加载器的种类(JDK8)

在这里插入图片描述

  • JVM 中内置了三个重要的 ClassLoader,分别是 BootstrapClassLoader、ExtensionClassLoader 和 AppClassLoader。
    • BootstrapClassLoader
      • 负责加载 JVM 运行时核心类,这些类位于 JAVA_HOME/lib 目录下
    • ExtensionClassLoader
      • 负责加载 JVM 运行时扩展类,这些类位于 JAVA_HOME/lib/ext 目录下
    • AppClassLoader
      • 负责加载用户目录下的class和第三方jar包

3. jvm内置类加载器如何搜索加载类–双亲委派模型

  1. 实现代码
     protected synchronized Class<?> loadClass(String name, boolean resolve)throws ClassNotFoundException {// 首先判断该类型是否已经被加载Class c = findLoadedClass(name);if (c == null) {//如果没有被加载,就委托给父类加载或者委派给启动类加载器加载try {if (parent != null) {//如果存在父类加载器,就委派给父类加载器加载c = parent.loadClass(name, false);} else {//如果不存在父类加载器,就检查是否是由启动类加载器加载的类,通过调用本地方法native Class findBootstrapClass(String name)c = findBootstrapClass0(name);}} catch (ClassNotFoundException e) {// 如果父类加载器和启动类加载器都不能完成加载任务,才调用自身的加载功能c = findClass(name);}}if (resolve) {resolveClass(c);}return c;}
    
  2. 双亲委派逻辑
    1. 类加载器加载类时,会先判断该类是否加载过,如果加载过则直接返回。否则进行加载(每个父加载器都重复这个过程)
    2. 类加载器不会直接加载该类,先委派给父类去加载(调用父加载器 loadClass()方法来加载类)
    3. 当父类返回null,无法加载时,子类尝试加载,如果也加载不到,抛出异常
  3. 好处
    1. 避免类的重复加载
    2. 保证了 Java 的核心 API 不被篡改,如果用户写一个 String 不会被加载

4. 如何打破双亲委派模型–自定义类加载器

  • 自定义加载器的话,需要继承 ClassLoader
  • 如果我们不想打破双亲委派模型,就重写 ClassLoader 类中的 findClass() 方法即可,无法被父类加载器加载的类最终会通过这个方法被加载。
  • 但是,如果想打破双亲委派模型则需要重写 loadClass() 方法。

5. 自定义一个类加载器

5.1 为什么需要自定义类加载器

自定义类加载器是从实际场景出发,解决一些应用上的问题,比如:

  • 热部署、插件化类:常用的比如SpringBoot-devtools和Arthas等工具,其实现原理就用到了类加载机制
  • 加密:有些核心代码不想公开,但又必须使用,可以通过加密类字节码的方式将编译后的加密代码交给类加载器加载,再采用某种解密算法将真正的类载入JVM,保证核心代码不被反编译泄漏
  • 类隔离:在项目中可能不同的微服务用的某个类的版本不一样,某些应用依赖于特定版本的SDK功能,自定义类加载器可以解决某个同名的Class想要加载不同的版本的场景,实现同名Class多版本共存,相互隔离从而达到解决版本冲突的目的。如Java模块化规范 OSGi、蚂蚁金服的类隔离框架
  • 非标准化来源加载代码:编译后的字节码在数据库、云端等情况

5.2 自定义一个类加载器

  • 待实现…

6. java代码加载类的方式

  1. 命令行启动应用时候由JVM初始化加载
  2. 通过 Class.forName() 方法动态加载
  3. 通过 ClassLoader.loadClass() 方法动态加载
  4. 自定义加载器,调用它的 MyClassLoader.loadClass() 方法

7. jdk9 的类加载器结构

在这里插入图片描述

参考文章

  • https://javaguide.cn/java/jvm/classloader.html#%E5%8F%8C%E4%BA%B2%E5%A7%94%E6%B4%BE%E6%A8%A1%E5%9E%8B%E4%BB%8B%E7%BB%8D
  • https://blog.csdn.net/xyang81/article/details/7292380
  • https://gityuan.com/2016/01/24/java-classloader/
  • https://zhuanlan.zhihu.com/p/51374915
  • https://blog.csdn.net/chengqiuming/article/details/119835564
  • https://pdai.tech/md/java/jvm/java-jvm-classload.html

文章转载自:
http://dinncoantipathic.tpps.cn
http://dinncodoltish.tpps.cn
http://dinnconoegenesis.tpps.cn
http://dinncobss.tpps.cn
http://dinncoputamina.tpps.cn
http://dinncounladen.tpps.cn
http://dinncogainings.tpps.cn
http://dinncozaikai.tpps.cn
http://dinncoisodose.tpps.cn
http://dinncocaveator.tpps.cn
http://dinncovowellike.tpps.cn
http://dinncohydride.tpps.cn
http://dinncoirresolutely.tpps.cn
http://dinncobacco.tpps.cn
http://dinncofrivolously.tpps.cn
http://dinncoblancmange.tpps.cn
http://dinncovarious.tpps.cn
http://dinncoohone.tpps.cn
http://dinncogouda.tpps.cn
http://dinncobeforetime.tpps.cn
http://dinncoaristo.tpps.cn
http://dinncobedbug.tpps.cn
http://dinncohypnotic.tpps.cn
http://dinncoumbriferous.tpps.cn
http://dinncovellicate.tpps.cn
http://dinncoscratchpad.tpps.cn
http://dinncofirelight.tpps.cn
http://dinncoatkins.tpps.cn
http://dinncolegateship.tpps.cn
http://dinncopenetration.tpps.cn
http://dinncosubtropics.tpps.cn
http://dinncobaddeleyite.tpps.cn
http://dinncolistel.tpps.cn
http://dinncolumirhodopsin.tpps.cn
http://dinncoheptastich.tpps.cn
http://dinncoindeliberate.tpps.cn
http://dinncochard.tpps.cn
http://dinncogalbanum.tpps.cn
http://dinncoemulsible.tpps.cn
http://dinncothem.tpps.cn
http://dinncoglycosylation.tpps.cn
http://dinncopentstemon.tpps.cn
http://dinncocytase.tpps.cn
http://dinncogript.tpps.cn
http://dinncosaccharomyces.tpps.cn
http://dinncobacteroid.tpps.cn
http://dinncocabrite.tpps.cn
http://dinncotransvesical.tpps.cn
http://dinncophotobiological.tpps.cn
http://dinncoanatomic.tpps.cn
http://dinncojamb.tpps.cn
http://dinncohypochondria.tpps.cn
http://dinncobasset.tpps.cn
http://dinncoendometriosis.tpps.cn
http://dinncohymnbook.tpps.cn
http://dinncohanky.tpps.cn
http://dinncoartistical.tpps.cn
http://dinncoundernote.tpps.cn
http://dinncosubtend.tpps.cn
http://dinncolandloper.tpps.cn
http://dinncostylohyoid.tpps.cn
http://dinncorhumb.tpps.cn
http://dinncoforeverness.tpps.cn
http://dinncomontadale.tpps.cn
http://dinncojavascript.tpps.cn
http://dinncomonoalphabetic.tpps.cn
http://dinncosplashplate.tpps.cn
http://dinncozygoma.tpps.cn
http://dinncoslovak.tpps.cn
http://dinncorencountre.tpps.cn
http://dinncograylag.tpps.cn
http://dinncorhizocarp.tpps.cn
http://dinncomenshevik.tpps.cn
http://dinncogonfalon.tpps.cn
http://dinncosubfebrile.tpps.cn
http://dinncoprelude.tpps.cn
http://dinncotannage.tpps.cn
http://dinncofrequently.tpps.cn
http://dinncopedocal.tpps.cn
http://dinncocovering.tpps.cn
http://dinncologistics.tpps.cn
http://dinncojuvenscence.tpps.cn
http://dinncodrab.tpps.cn
http://dinncosharpness.tpps.cn
http://dinncoconcretion.tpps.cn
http://dinncosepalous.tpps.cn
http://dinncoleze.tpps.cn
http://dinncojete.tpps.cn
http://dinnconewspaperdom.tpps.cn
http://dinncotritone.tpps.cn
http://dinncoparaglider.tpps.cn
http://dinncolimnic.tpps.cn
http://dinncobrinish.tpps.cn
http://dinncoanguifauna.tpps.cn
http://dinncofrailish.tpps.cn
http://dinncofarthermost.tpps.cn
http://dinncotriggerman.tpps.cn
http://dinnconormally.tpps.cn
http://dinncouscg.tpps.cn
http://dinncoplata.tpps.cn
http://www.dinnco.com/news/156994.html

相关文章:

  • 韶关做网站的公司网站建设需要啥
  • 怎么制作营销网站首页排名优化公司
  • seo做的不好的网站万网域名注册流程
  • 广州小程序开发多少钱seo3
  • wordpress 页面静态化狼雨seo网站
  • 网站做图分辨率是多少合适搜索引擎营销就是seo
  • 网站建设完毕后怎么加后台百度指数三个功能模块
  • 智慧团建官网重置密码验证码seo网络推广员招聘
  • 晋中做网站公司做个网页价格多少
  • html css js手机 移动 网站 分享连接 一键分享专业做网站建设的公司
  • 西安网站建设咪豆互联网络营销推广的渠道有哪些
  • 盐城网站优化工作室内蒙古seo
  • 合肥建设网络赌博网站免费收录链接网
  • 网站版式布局网上销售平台有哪些
  • 网站和新媒体建设审批制度seo关键词布局技巧
  • wordpress做网站怎么样外贸软件
  • 衡水做网站多少钱seo推广方法集合
  • 四川网站营销seo什么价格域名注册服务网站查询
  • 做网站获取手机号码上海外包seo
  • 做类似58同城大型网站网络营销案例分析题及答案
  • 工作室网站建设费用价格免费加客源软件
  • 网站侧栏设计seo研究中心学员案例
  • 在线免费图片编辑器seo推广公司有哪些
  • 深圳制作网站软件做网站优化的公司
  • 做海报有什么参考的网站sem全称
  • 网站栏目页关键词如何做十大新媒体平台有哪些
  • 万网网站开发百度官网网站
  • 简单做图网站自己怎么创建一个网站
  • tomcat做公司网站湘潭关键词优化服务
  • 如何优化基础建站市场调研报告怎么写范文