クエリのタイムアウトを秒単位ではなくミリ秒単位で設定する方法はありますか? java.sql.Statement API には秒単位のメソッドしかありませんが、私のユース ケースでは 1 秒でも遅すぎます。
Java API: http://docs.oracle.com/javase/7/docs/api/java/sql/Statement.html#setQueryTimeout(int)
Oracle DB を使用しています。
クエリのタイムアウトを秒単位ではなくミリ秒単位で設定する方法はありますか? java.sql.Statement API には秒単位のメソッドしかありませんが、私のユース ケースでは 1 秒でも遅すぎます。
Java API: http://docs.oracle.com/javase/7/docs/api/java/sql/Statement.html#setQueryTimeout(int)
Oracle DB を使用しています。
これは非常に複雑ですが、うまくいく可能性があります:
Future<ResultType>
には「get(Long, TimeUnit)」関数があり、設定されたタイムアウトまでブロックします-これは設定可能な粒度を持っています(少なくともそのようになることを約束します...ほぼJavaコードで次のようなもの:
public class MyCallable implements Callable<ResultType> {
@Override
public ResultType call() throws Exception {
//do query, with 1s timeout - that way no thread will be busy for more than 1s
return result;
}
}
リクエストの処理
ExecutorService threadPool; //initialised somewhere earlier
Future<ResultType> futureResult = threadPool.submit(new MyCallable());
try {
ResultType result = futureResult.get(100, TimeUnit.MILLISECONDS);
//results received in time, do the processing here
} catch(TimeoutException e) {
//request too slow -- handle it
} catch( other exceptions...) { ... }