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

     

  • 相关阅读:
    字符串哈希之Rabin-Karp,poj1200
    字符串哈希之ELFHash,poj2503
    dfs之n的全排列
    几大排序算法(选择,插入)
    dfs之地图染色
    单纯的dfs
    dfs之记忆化搜索(字符串匹配,位置相对变)
    STL之map的一种用法
    JAVA之大数处理,有简单方法不用是sb
    ACM之素数环(DFS)
  • 原文地址:https://www.cnblogs.com/yuyutianxia/p/3487219.html
Copyright © 2011-2022 走看看