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 閱讀(120) 評論(0)  編輯  收藏


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


          網站導航:
           

          My Links

          News

          留言簿(18)

          隨筆檔案

          相冊

          搜索

          最新評論

          閱讀排行榜

          主站蜘蛛池模板: 莫力| 肃宁县| 辉南县| 丰顺县| 三河市| 吉安市| 海南省| 都匀市| 阜康市| 阜新| 化隆| 甘谷县| 平利县| 德江县| 长沙县| 桦甸市| 延庆县| 申扎县| 仙桃市| 托克托县| 正镶白旗| 岐山县| 赤壁市| 太原市| 财经| 类乌齐县| 民乐县| 商丘市| 马尔康县| 南通市| 灵武市| 盘锦市| 潍坊市| 大渡口区| 山东| 安国市| 唐海县| 周宁县| 修水县| 繁昌县| 庆安县|