示例#1
0
 /**
  * Shutdown a specific member.
  *
  * @param m
  */
 private void shutdownMember(MemberInfo m) {
   ResourceManager rm = GroupMember.memberInfoToResourceManager(m);
   if (rm != null) {
     try {
       rm.shutdown(FORCE_SHUTDOWN);
     } catch (Exception e) {
       // do nothing.
     }
   }
 }
  @BeforeClass
  public static void initialize() throws InterruptedException {
    Runtime rt = Runtime.getRuntime();

    rt.gc();
    freeMemory_preUse = rt.freeMemory();

    ResourceManager rm = new ResourceManager();

    for (int i = 0; i < 1000; i++) {
      Object key = Integer.toString(i);
      keyList.add(key);
      resourceList.add(rm.getResource(key));
    }

    rt.gc();
    freeMemory_useRes = rt.freeMemory();

    for (int i = 0; i < 1000; i++) {
      Object key = keyList.get(i);
      Resource res = resourceList.get(i);
      res.use(key);
    }

    for (int i = 0; i < 1000; i++) {
      Resource res = resourceList.get(i);
      res.release();
    }

    keyList.clear(); // リソースへの参照をすべて削除
    resourceList.clear(); // リソースへの参照をすべて削除

    rm.shutdown();
    rt.gc();

    rm.reaper.join();

    rt.gc();
    freeMemory_clearRes = rt.freeMemory();

    System.out.println("freeMemory_preUse  :" + freeMemory_preUse);
    System.out.println("freeMemory_useRes  :" + freeMemory_useRes);
    System.out.println("freeMemory_clearRes:" + freeMemory_clearRes);
  }