示例#1
0
 @Override
 public void run() {
   long sleep = JefConfiguration.getLong(DbCfg.DB_CONNECTION_LIVE, 60000);
   ThreadUtils.doSleep(sleep);
   try {
     while (alive) {
       doWork();
       ThreadUtils.doSleep(sleep);
     }
   } catch (Exception e) {
     log.error("", e);
   }
 }
示例#2
0
  //	@Test
  @Ignore
  public void testThread() throws InterruptedException {
    IUserManagedPool pool = super.getPool();
    MyThread[] threads = new MyThread[CONN_LOOPS];
    for (int j = 0; j < CONN_LOOPS; j++) {
      threads[j] = new MyThread(pool, j, true, count);
    }
    for (int j = 0; j < CONN_LOOPS; j++) {
      threads[j].start();
    }

    while (count.get() < CONN_LOOPS && countException.get() == 0) {
      // 实时监控连接池的状态
      String msg = "当前连接池数量:" + pool.getStatus();
      ConnPrintOutUtil.print(log, ConnPrintOutUtil.INFO, msg);
      ThreadUtils.doWait(super.getPool());
    }
    Thread.sleep(1000);
    // 如果结果不抛出异常 则说明case正确
    if (countException.get() == 0) {
      ConnPrintOutUtil.printSuccess(log);
    } else {
      ConnPrintOutUtil.printFailure(log);
    }
  }
示例#3
0
    @Override
    public void run() {
      // TODO Auto-generated method stub
      try {

        for (int i = 0; i < 100; i++) {
          // 获取连接
          //					pool.getConnection(index);
          IConnection conn = pool.poll();

          // 进行休眠
          int t = rd.nextInt(50) + 1000;
          Thread.sleep(t);

          // 查询表并且释放连接
          consultTable();
          if (isRelease) {
            conn.close();
          }
          Thread.sleep(1 * 1000);
          if (i % 10 == 0) {
            ThreadUtils.doNotify(pool);
          }
        }

      } catch (SQLException e) {
        // TODO Auto-generated catch blockx
        String msg = "thread " + index + " has exception";
        ConnPrintOutUtil.print(log, ConnPrintOutUtil.WARN, msg);
        countException.incrementAndGet();
        count.incrementAndGet();
        ThreadUtils.doNotify(pool);
      } catch (Exception e) {
        // TODO: handle exception
        ConnPrintOutUtil.print(log, ConnPrintOutUtil.ERROR, e.getLocalizedMessage());
        ConnPrintOutUtil.printFailure(log);
      }
      count.incrementAndGet();
      ThreadUtils.doNotify(pool);
    }