zoukankan      html  css  js  c++  java
  • 类加载(二)

    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').

     

  • 相关阅读:
    设计模式(23)>解释器模式 小强斋
    设计模式(21)>享元模式 小强斋
    访问者模式与双分派 小强斋
    将BMP格式的灰度图像或24位真彩图像二值化
    如何使用自定义Title
    ACM. Digital Roots
    jpegEncode
    ACM.Ones
    剩余定理
    ACM.DNA Sorting
  • 原文地址:https://www.cnblogs.com/yuyutianxia/p/3487219.html
Copyright © 2011-2022 走看看