下面是我写的代码,作用是开启n个线程,执行插入语句
然后...没发现有什么区别....
public class Task implements Runnable {
int id;
CyclicBarrier barrier;
public Task(int _id, CyclicBarrier _barrier) {
id = _id;
barrier = _barrier;
}
@Override
public void run() {
System.out.println(id + " begin");
Dao dao = new Dao();
int n = 1000;
for (int i = 0; i < n; i++) {
dao.add("insert into test(id, name) values(?, ?)", 1, 1);
}
try {
barrier.await();
} catch (InterruptedException | BrokenBarrierException e) {
e.printStackTrace();
}
System.out.println(id + " end");
}
}
public class Task implements Runnable {
int id;
CountDownLatch latch;
public Task(int _id, CountDownLatch _latch) {
id = _id;
latch = _latch;
}
@Override
public void run() {
System.out.println(id + "-begin");
addOracle();
latch.countDown();
System.out.println(id + "-end");
}
public void addOracle() {
Dao dao = new Dao();
int n = 100;
for (int i = 0; i < n; i++) {
dao.add("insert into test(id, name) values(?, ?)", i, i);
}
}
}