Beispiel #1
0
 public void consultTable() throws SQLException {
   String sql = "select count(*) from DEPT";
   IConnection conn = pool.poll();
   PreparedStatement ps = conn.prepareStatement(sql);
   ResultSet rs = ps.executeQuery();
   if (rs.next()) {
     if (ConnPrintOutUtil.isOnServer()) {
       Assert.assertEquals(4, rs.getInt(1));
     }
   }
 }
Beispiel #2
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);
    }