• 类加载(二)


    1.Class 的 getClassLoader()

      Returns the class loader for the class. Some implementations may use null to represent the bootstrap class loader.

    This method will return null in such implementations if this class was loaded by the bootstrap class loader.

    2.Thread 的 getContextClassLoader()

      Returns the context ClassLoader for this Thread. The context ClassLoader is provided by the creator of the thread for

    use by code running in this thread when loading classes and resources. If not set, the default is the ClassLoader context 

    of the parent Thread. The context ClassLoader of the primordial thread is typically set to the class loader used to load

    the application.

      For example, JNDI and JAXP used thread's ClassLoader. You had better to use thread's ClassLoader in your own code when your

    code need to deployed on J2EE container.

    3.ClassLoader.getResourceAsStream() 与 Class.getResourceAsStream()的区别

    Class.getResourceAsStream()

      Finds a resource with a given name. The rules for searching resources associated with a given class are implemented by the defining 

    class loader of the class. This method delegates to this object's class loader. If this object was loaded by the bootstrap class loader,

    the method delegates to ClassLoader.getSystemResourceAsStream(java.lang.String). Before delegation, an absolute resource name is

    constructed from the given resource name using this algorithm:

    • If the name begins with a '/' ('u002f'), then the absolute name of the resource is the portion of the name following the '/'.
    • Otherwise, the absolute name is of the following form:
      modified_package_name/name

      Where the modified_package_name is the package name of this object with '/' substituted for '.' ('u002e').

     

  • 相关阅读:
    终端解析 规格严格
    用HQ时,出现了一个Bug 规格严格
    GC这篇文章介绍得很基本 规格严格
    DB2协议研究 规格严格
    JVM monitoring 规格严格
    很有趣的GC内容 规格严格
    在linux内核中修改TCP MSS值 规格严格
    最近为项目写了一个调试模块,由此想到的一些内容 规格严格
    Java中国象棋博弈程序探秘[3]——着法合法性判断
    NetBeans 时事通讯(刊号 # 10 Jun 03, 2008)
  • 原文地址:https://www.cnblogs.com/yuyutianxia/p/3487219.html
Copyright © 2020-2023  润新知