王洪伟的专栏

http://blog.teamlet.org

用户操作
[即时聊天] [发私信] [加为好友]
王洪伟ID:teamlet
168488次访问,排名451好友1人,关注者57
10年软件开发设计经验,专注J2EE领域的技术架构和应用.
teamlet的文章
原创 100 篇
翻译 9 篇
转载 67 篇
评论 146 篇
teamlet的公告

本站采用创作共用版权协议, 要求署名、非商业用途和相同方式共享. 转载本站内容必须也遵循“署名-非商业用途-相同方式共享”的创作共用协议.

关注SOA技术的发展,跟进SCA技术的理论和实现,努力实践。愿与同行者一起分享,互相勉励,共同进步。
最近评论
myself:<configuration>
<source>1.5</source>
<target>1.5</target>
<maxmem>256M</maxmem>
<encoding>UTF-8</encoding>
<……
zhi:您好!!
能不能给我也发一份源码过来!谢谢
zhi@tuanke.net
lai:2008-9-4 13:52:56 org.apache.catalina.core.ApplicationDispatcher invoke
严重: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has alread……
lai:2008-9-4 13:52:56 org.apache.catalina.core.ApplicationDispatcher invoke
严重: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has alread……
lai:2008-9-4 13:52:55 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet AxisServlet threw exception
java.lang.NullPointerException
at org.apache.axi……
文章分类
收藏
    相册
    资源联接
    Apache Tuscany
    Cruise Control
    Open CSA
    OSOA
    SOA Tools Project
    Theserverside
    中国Java开发网
    满江红
    知识共享@中国大陆
    左邻右舍
    donews的blog
    msn的blog
    Tuscany中文社区
    我用Subversion
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 equinox实现Class Loader机制的代码解读(1)收藏

    新一篇: equinox实现Class Loader机制的代码解读(2) | 旧一篇: 为什么学习戴明的管理方法

     

     

    equinox 环境下每一个bundle都是由独立的classLoader实现类的装载的。在OSGi Framework中,Bundle是模块化管理的单元,所有的应用和资源都必须以Bundle作为载体。每个Bundle都有自己的Class Loader,不同Bundle之间(在同一个VM中)可以通过Import和Export机制共享或者隐藏Package。Class Loader建立一种Loading Class的代理模型,来实现资源的共享或隐藏。

    下面是equinox实现的类的装载代码:

     

        Class findClass(String name, boolean checkParent) throws ClassNotFoundException {

            String pkgName 
    = getPackageName(name);
            
    // follow the OSGi delegation model
            if (checkParent && parent != null) {
                
    if (name.startsWith(JAVA_PACKAGE))
                  
    // 1) if startsWith "java." delegate to parent and terminate search
                  
    // we want to throw ClassNotFoundExceptions if a java.* class cannot be loaded from the parent.
                    return parent.loadClass(name);
                
    else if (isBootDelegationPackage(pkgName))
                    
    // 2) if part of the bootdelegation list then delegate to parent and continue of failure
                    try {
                        
    return parent.loadClass(name);
                    } 
    catch (ClassNotFoundException cnfe) {
                        
    // we want to continue
                    }
            }

            Class result 
    = null;
            
    // 3) search the imported packages
            PackageSource source = findImportedSource(pkgName);
            
    if (source != null) {
                
    // 3) found import source terminate search at the source
                result = source.loadClass(name);
                
    if (result != null)
                    
    return result;
                
    throw new ClassNotFoundException(name);
            }
            
    // 4) search the required bundles
            source = findRequiredSource(pkgName);
            
    if (source != null)
                
    // 4) attempt to load from source but continue on failure
                result = source.loadClass(name);
            
    // 5) search the local bundle
            if (result == null)
                result 
    = findLocalClass(name);
            
    if (result != null)
                
    return result;
            
    // 6) attempt to find a dynamic import source; only do this if a required source was not found
            if (source == null) {
                source 
    = findDynamicSource(pkgName);
                
    if (source != null)
                    result 
    = source.loadClass(name);
            }
            
    // do buddy policy loading
            if (result == null && policy != null)
                result 
    = policy.doBuddyClassLoading(name);
            
    // last resort; do class context trick to work around VM bugs
            if (result == null && findParentResource(name))
                result 
    = parent.loadClass(name);
            
    if (result == null)
                
    throw new ClassNotFoundException(name);
            
    return result;
        }

     

    从上面的代码可以看出什么呢?

    1、解释了为什么在equinox的bundle中不需要引入java.*的包,而需要引入javax.*的包。
          参见 equinox实现Class Loader机制的代码解读(2)

    2、解释了如果import一个包名和当前bundle中的包名相同会发生什么。
         参见equinox实现Class Loader机制的代码解读(3)

    3、解释了如果使用了动态引入后,再次import相同的包产生的影响。

    请参见后面的系列文章。

    发表于 @ 2008年03月13日 22:33:00|评论(loading...)|编辑

    新一篇: equinox实现Class Loader机制的代码解读(2) | 旧一篇: 为什么学习戴明的管理方法

    评论:没有评论。

    发表评论  


    登录
    Csdn Blog version 3.1a
    Copyright © teamlet