提交 2962ea18 authored 作者: Noel Grandin's avatar Noel Grandin

cleanup ExecutorService after test

上级 9fb8b74e
...@@ -319,58 +319,61 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -319,58 +319,61 @@ public class TestMultiThread extends TestBase implements Runnable {
conn.close(); conn.close();
// create views that reference the common views in different threads // create views that reference the common views in different threads
final ExecutorService executor = Executors.newFixedThreadPool(8); final ExecutorService executor = Executors.newFixedThreadPool(8);
final ArrayList<Future<Void>> jobs = new ArrayList<Future<Void>>(); try {
for (int i = 0; i < 1000; i++) { final ArrayList<Future<Void>> jobs = new ArrayList<Future<Void>>();
final int j = i; for (int i = 0; i < 1000; i++) {
jobs.add(executor.submit(new Callable<Void>() { final int j = i;
@Override jobs.add(executor.submit(new Callable<Void>() {
public Void call() throws Exception { @Override
final Connection conn2 = getConnection(url); public Void call() throws Exception {
Statement stat2 = conn2.createStatement(); final Connection conn2 = getConnection(url);
Statement stat2 = conn2.createStatement();
stat2.execute("CREATE VIEW INVOICE_VIEW" + j
+ " as SELECT * FROM INVOICE_VIEW"); stat2.execute("CREATE VIEW INVOICE_VIEW" + j
+ " as SELECT * FROM INVOICE_VIEW");
// the following query intermittently results in a
// NullPointerException // the following query intermittently results in a
stat2.execute("CREATE VIEW INVOICE_DETAIL_VIEW" + j // NullPointerException
+ " as SELECT DTL.* FROM INVOICE_VIEW" + j stat2.execute("CREATE VIEW INVOICE_DETAIL_VIEW" + j
+ " INV JOIN INVOICE_DETAIL_VIEW DTL " + " as SELECT DTL.* FROM INVOICE_VIEW" + j
+ "ON INV.INVOICE_ID = DTL.INVOICE_ID" + " INV JOIN INVOICE_DETAIL_VIEW DTL "
+ " WHERE DESCRIPTION='TEST'"); + "ON INV.INVOICE_ID = DTL.INVOICE_ID"
+ " WHERE DESCRIPTION='TEST'");
ResultSet rs = stat2
.executeQuery("SELECT * FROM INVOICE_VIEW" + j); ResultSet rs = stat2
rs.next(); .executeQuery("SELECT * FROM INVOICE_VIEW" + j);
rs.close(); rs.next();
rs.close();
rs = stat2.executeQuery(
"SELECT * FROM INVOICE_DETAIL_VIEW" + j); rs = stat2.executeQuery(
rs.next(); "SELECT * FROM INVOICE_DETAIL_VIEW" + j);
rs.close(); rs.next();
rs.close();
stat.close();
conn.close(); stat.close();
return null; conn.close();
} return null;
})); }
} }));
// check for exceptions }
for (Future<Void> job : jobs) { // check for exceptions
try { for (Future<Void> job : jobs) {
job.get(); try {
} catch (ExecutionException ex) { job.get();
// ignore timeout exceptions, happens periodically when the machine is really } catch (ExecutionException ex) {
// busy and it's not the thing we are trying to test // ignore timeout exceptions, happens periodically when the machine is really
if (!(ex.getCause() instanceof JdbcSQLException) // busy and it's not the thing we are trying to test
|| ((JdbcSQLException) ex.getCause()) if (!(ex.getCause() instanceof JdbcSQLException)
.getErrorCode() != ErrorCode.LOCK_TIMEOUT_1) { || ((JdbcSQLException) ex.getCause())
throw ex; .getErrorCode() != ErrorCode.LOCK_TIMEOUT_1) {
throw ex;
}
} }
} }
} finally {
executor.shutdown();
executor.awaitTermination(20, TimeUnit.SECONDS);
} }
executor.shutdown();
executor.awaitTermination(20, TimeUnit.SECONDS);
deleteDb("lockMode"); deleteDb("lockMode");
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论