我想写一个SwingWorker
,当用户取消任务时,它是:1)取消PreparedStatement
,2)中止Connection
。
下面是一些代码来说明:
class Task extends SwingWorker<Void, Void> {
Connection conn;
PreparedStatement p_stmt;
@Override
protected Void doInBackground() throws Exception {
ResultSet results = p_stmt.executeQuery();
while(results.next()) {
if(isCancelled())
return;
}
return null;
}
void cancell() {
cancel(true);
try {
p_stmt.cancel();
conn.abort(/* How do I properly implement Executor? */);
} catch (SQLException e) {
handleError(e);
}
}
@Override
protected void done() {
try {
get();
} catch (ExecutionException | InterruptedException e) {
handleError(e);
}
}
}
static void handleError(Exception e) {
// ...
}
此行:
conn.abort(/* How do I properly implement Executor? */);
这是我感兴趣的那一行。我应该传递给Connection::abort
吗?