提交 98624f57 编写于 作者: Z zyyang

change

上级 967f1ab2
...@@ -172,20 +172,14 @@ public class TSDBStatement implements Statement { ...@@ -172,20 +172,14 @@ public class TSDBStatement implements Statement {
} }
public boolean execute(String sql) throws SQLException { public boolean execute(String sql) throws SQLException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
System.out.println(Thread.currentThread().getName() + " before execute " + sdf.format(new Date()) + "=====> isclosed: " + isClosed);
if (isClosed) { if (isClosed) {
System.out.println(Thread.currentThread().getName() + " will throw " + sdf.format(new Date()) + "=====> isclosed: " + isClosed);
throw new SQLException("Invalid method call on a closed statement."); throw new SQLException("Invalid method call on a closed statement.");
} }
boolean res = true; boolean res = true;
System.out.println(Thread.currentThread().getName() + " before JNI " + sdf.format(new Date()) + "=====> isclosed: " + isClosed);
pSql = this.connector.executeQuery(sql); pSql = this.connector.executeQuery(sql);
System.out.println(Thread.currentThread().getName() + " after JNI " + sdf.format(new Date()) + "=====> isclosed: " + isClosed);
long resultSetPointer = this.connector.getResultSet(); long resultSetPointer = this.connector.getResultSet();
if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) { if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) {
this.connector.freeResultSet(pSql); this.connector.freeResultSet(pSql);
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
...@@ -194,7 +188,6 @@ public class TSDBStatement implements Statement { ...@@ -194,7 +188,6 @@ public class TSDBStatement implements Statement {
this.connector.freeResultSet(pSql); this.connector.freeResultSet(pSql);
res = false; res = false;
} }
System.out.println(Thread.currentThread().getName() + " after execute " + System.currentTimeMillis() + " =====> isclosed: " + isClosed);
return res; return res;
} }
......
...@@ -30,13 +30,14 @@ public class InvalidResultPointerExceptionTest { ...@@ -30,13 +30,14 @@ public class InvalidResultPointerExceptionTest {
@Test @Test
public void testInvalidResultPointerException() { public void testInvalidResultPointerException() {
try (Connection conn = TSDBCommon.getConn("localhost")) { try (Connection conn = TSDBCommon.getConn("localhost")) {
Statement stmt = conn.createStatement();
List<Thread> threads = IntStream.range(1, 2).boxed().map(i -> new Thread(() -> { List<Thread> threads = IntStream.range(1, 2).boxed().map(i -> new Thread(() -> {
while (true) { while (true) {
String sql = "insert into irp_test.weather values(now, " + random.nextInt(100) + ")"; String sql = "insert into irp_test.weather values(now, " + random.nextInt(100) + ")";
try { try {
Statement stmt = conn.createStatement();
stmt.execute(sql); stmt.execute(sql);
stmt.close();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -49,11 +50,12 @@ public class InvalidResultPointerExceptionTest { ...@@ -49,11 +50,12 @@ public class InvalidResultPointerExceptionTest {
} }
}, "Thread-" + i)).collect(Collectors.toList()); }, "Thread-" + i)).collect(Collectors.toList());
for (int i = 0; i < threads.size(); i++) { for (Thread thread : threads)
threads.get(i).join(); thread.start();
for (Thread thread : threads) {
thread.join();
} }
stmt.close();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册