Package com.taobao.tddl.jdbc.group.integration

Source Code of com.taobao.tddl.jdbc.group.integration.DiamondMultiThreadTest$MyThread

/*(C) 2007-2012 Alibaba Group Holding Limited. 
*This program is free software; you can redistribute it and/or modify 
*it under the terms of the GNU General Public License version 2 as 
* published by the Free Software Foundation. 
* Authors: 
*   junyu <junyu@taobao.com> , shenxun <shenxun@taobao.com>, 
*   linxuan <linxuan@taobao.com> ,qihao <qihao@taobao.com>  
*/ 
package com.taobao.tddl.jdbc.group.integration;

import org.junit.Test;

import com.taobao.diamond.manager.DiamondManager;
import com.taobao.diamond.manager.ManagerListener;
import com.taobao.diamond.manager.impl.DefaultDiamondManager;
import com.taobao.tddl.jdbc.group.TGroupDataSource;

public class DiamondMultiThreadTest {
  public static final String appName = "unitTest";

  public static class MyThread extends Thread {
    DiamondManager diamondManager;

    MyThread(String dataId, int index) {
      super("MyThread-" + index);
      diamondManager = new DefaultDiamondManager(dataId, (ManagerListener) null);
      //System.out.println(this + " diamondManager = "+diamondManager);
    }

    public void run() {
      if(ds!=null) {
        ds.init();
        return;
      }
      //System.out.println(this + " is running");

      String configInfo = diamondManager.getConfigureInfomation(0);
      System.out.println(this + " get configInfo = " + configInfo);

      //System.out.println(this + " ended");
    }
   
    TGroupDataSource ds;

    MyThread(TGroupDataSource ds) {
      this.ds = ds;
    }
  }

  @Test
  public void ����ִ�ж���߳�_���漰TAtomDataSource() throws Exception {
    int size = 6;
    MyThread[] myThreads = new MyThread[size];
    for (int i = 1; i <= size; i++) {
      MyThread t = new MyThread("DiamondMultiThreadTest" + i, i);
      t.start();
     
      myThreads[i-1] = t;
    }
   
    for (int i = 0; i < size; i++) {
      myThreads[i].join();
    }
  }
 
  @Test
  public void ����ִ�ж���߳�_���漰TAtomDataSource() throws Exception {
    int size = 6;
    for (int i = 1; i <= size; i++) {
      MyThread t = new MyThread("DiamondMultiThreadTest" + i, i);
      t.start();
      t.join();
    }
  }
 
  @Test
  public void ����ִ�ж���߳�_�漰TAtomDataSource() throws Exception {
    int size = 3;
    MyThread[] myThreads = new MyThread[size];
    for (int i = 1; i <= size; i++) {

      MyThread t = new MyThread(new TGroupDataSource("myDbGroupKey" + i, appName));
      t.start();
      myThreads[i-1] = t;
    }
   
    for (int i = 1; i <= size; i++) {
      myThreads[i-1].join();
    }
  }
 
  @Test
  public void ����ִ�ж���߳�_�漰TAtomDataSource() throws Exception {
    int size = 3;
    for (int i = 1; i <= size; i++) {
      MyThread t = new MyThread(new TGroupDataSource("myDbGroupKey" + i, appName));
      t.start();
      t.join();
    }
  }
}
TOP

Related Classes of com.taobao.tddl.jdbc.group.integration.DiamondMultiThreadTest$MyThread

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.