日期:2014-05-16 浏览次数:20930 次
for (int i = 1; i <= 20; i++) {
new Thread(new Runnable() {
public void run() {
Connection conn = null;
try {
conn = DBUtils.getConnection();
synchronized (counter) {
System.out.print(Thread.currentThread().getName());
System.out.print(" counter = " + counter++
+ " conn = " + conn);
System.out.println();
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}).start();
}