亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1540 | 回復(fù): 0
打印 上一主題 下一主題

fighting with the tricky ClassLoader [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2005-08-07 00:40 |只看該作者 |倒序?yàn)g覽

The conceptions of ClassLoader are the most tricky ones in the javaworld...
一想到Reflection, ClassLoader就像做惡夢(mèng), 但他們確實(shí)非常有趣, 每一個(gè)問題都是一個(gè)挑戰(zhàn). 和這些東西鏖戰(zhàn)幾個(gè)月后, 經(jīng)過無數(shù)測(cè)試, 今天又弄明白一個(gè)概念, 所以寫下來, 希望能對(duì)大家有所幫助, 同時(shí)也加深我的記憶.
假設(shè)有兩個(gè)ClassLoader, parentLoader and childLoader, parentLoader is the parent classloader of the childLoader. Now, according to java's defalt delegation class loading mechanism, when the child class loader wants to load a class, say com.foo.Bar, it first asks his father, hey, dad, do you have the class com.foo.Bar previously loaded or in your classpath, then, recursively, the father does the same thing. If the father answered yes, then it returned the class to his son, if not, he told the son, no, I don't have it previously loaded or in my classpath, finally, the son search his own classpath, if it still can not find the class in his own classpath, then, a ClassNotFoundException thrown. This is the story in the java class loading world.
Now the child class loader hopes to get a class com.foo.Bar. but the class is found in the parent class loader's classpath.
ClassLoader parentLoader = new URLClassLoader(someURLs, null);
ClassLoader childLoader = new URLClassLoader(someOtherUrls, parentLoader);
Class c = childLoader.loadClass("com.foo.Bar");
Method m = c.getMethod("main", new Class[] { args.getClass() });
m.invoke(null, new Object[] { args });
Now, everything is happening in the new world(classpath). And, suddenly, a ClassNotFoundException is thrown when loading a class within the child class loader occured. Then, I move the class desired in to the father's classpth, it returns calm. So we see, everything is now happening in the father's world!! We load a class from the child class loader, but the class is actually found in the father's class loader, and we invoke a method on the class loaded. Then next time within the method, it load a new class, it search from the parent class loader, not the child. Really tricky!


本文來自ChinaUnix博客,如果查看原文請(qǐng)點(diǎn):http://blog.chinaunix.net/u/4960/showart_39476.html
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP