zoukankan      html  css  js  c++  java
  • http://classworlds.codehaus.org/apiusage.html

    API Usage

    The Java API can be used to create new realms and connect realms together through importation of specific packages.

    The core of the classworlds infrastructure is the ClassWorld class. An application must create a ClassWorld instance. It is advisable to store the instance as a singleton or some other handy location.

    ClassWorld world = new ClassWorld();
    

    Once a ClassWorld is created, realms within it can be created. These realms effectively only allow loading of the core JVM classes.

    ClassWorld world = new ClassWorld();
    
    ClassRealm containerRealm    = world.newRealm( "container" );
    ClassRealm logComponentRealm = world.newRealm( "logComponent" );
    

    In order to make each ClassRealm useful, constituent must be added to that each can provide certain classes.

    containerRealm.addConstituent( containerJarUrl );
    logComponentRealm.addConstituent( logComponentJarUrl );
    

    Now, links between the various realms need to be created to allow classes loaded from one to be available to classes loaded in another.

    logComponentRealm.importFrom( "container", 
                                  "com.werken.projectz.component" );
    

    The container implementation can then be loaded from it's realm and used.

    Class containerClass = containerRealm.loadClass( CONTAINER_CLASSNAME );
    
    MyContainer container = (MyContainer) containerClass.newInstance();
    
    Thread.currentThread().setContextClassLoader( containerRealm.getClassLoader() );
    
    container.run();
    

    Ideally, the container itself would be responsible for creating a ClassRealm for each component that's loaded, and importing the component contract interfaces into the component's ClassRealm and using loadClass(..) to gain entry into the sandboxed component realm.

  • 相关阅读:
    Java作业十(2017-11-8)
    Java作业九(2017-11-6)
    Java作业八(2017-10-30)
    Java作业七(2017-10-30)
    Java作业六(2017-10-30)
    Java作业五(2017-10-15)
    如何获取jqGrid中选择的行的数据
    如何修改WAMP中mysql默认空密码
    为 PhpStorm 配置 Xdebug 来调试代码
    MySQL load_file()/into outfile路径问题总结
  • 原文地址:https://www.cnblogs.com/heidsoft/p/4179249.html
Copyright © 2011-2022 走看看