afunms

          My Software,My Dream—Forge a more perfect NMS product.

          difference between two classLoaders

          struts里總用到Thread.currentThread().getContextClassLoader()
          而我們一般只用到Class.forName()或Class.getClassLoader()

          所以想知道二者有什么區別,以下是從網上找到的:


          Classloader存在下面問題:
          在一個JVM中可能存在多個ClassLoader,每個ClassLoader擁有自己的NameSpace。
          一個ClassLoader只能擁有一個class對象類型的實例,但是不同的ClassLoader可能
          擁有相同的class對象實例,這時可能產生致命的問題。如ClassLoaderA,裝載了
          類A的類型實例A1,而ClassLoaderB,也裝載了類A的對象實例A2。邏輯上講A1=
          A2,但是由于A1和A2來自于不同的ClassLoader,它們實際上是完全不同的,
          如果A中定義了一個靜態變量c,則c在不同的ClassLoader中的值是不同的。

          Class.getClassLoader() returns the ClassLoader that loaded the class it
          is invoked on.

          Thread.getContextClassLoader() returns the ClassLoader set as the
          context ClassLoader for the Thread it is invoked on, which can be
          different from the ClassLoader that loaded the Thread class itself if
          the Thread's setContextClassLoader(ClassLoader) method has been invoked.
          This can be used to allow the object starting a thread to specify a
          ClassLoader that objects running in the thread should use, but the
          cooperation of some of those objects is required for that to work.


           

          posted on 2007-10-16 17:41 afunms 閱讀(121) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          My Links

          News

          留言簿(18)

          隨筆檔案

          相冊

          搜索

          最新評論

          閱讀排行榜

          主站蜘蛛池模板: 晋中市| 古田县| 靖远县| 定陶县| 龙游县| 平和县| 贵州省| 太谷县| 阳春市| 墨玉县| 正阳县| 江西省| 上栗县| 东平县| 萨迦县| 遂溪县| 双柏县| 义马市| 钦州市| 鱼台县| 宁武县| 虎林市| 鄄城县| 阿瓦提县| 报价| 宣威市| 苏尼特右旗| 澄迈县| 乐陵市| 翁牛特旗| 洛浦县| 合川市| 柳河县| 霍城县| 资溪县| 婺源县| 佛冈县| 那曲县| 都匀市| 盈江县| 中江县|