이것은 JDBC 드라이버가 아닌 Java에서 발생하는 문제입니다. 특정 상황에서 소켓 연결 호출은 제한 시간 매개 변수를 무시하고 반환하는 데 몇 분이 걸릴 수 있습니다. 방화벽이 포트를 차단할 때 이런 일이 발생합니다. 그것은 모든 TCP 연결 (HTTP, RMI)에 발생합니다.
내가 찾을 수있는 유일한 솔루션은이 같은 다른 스레드에서 연결을 열 수 있습니다
,
private static final ExecutorService THREADPOOL
= Executors.newCachedThreadPool();
private static <T> T call(Callable<T> c, long timeout, TimeUnit timeUnit)
throws InterruptedException, ExecutionException, TimeoutException
{
FutureTask<T> t = new FutureTask<T>(c);
THREADPOOL.execute(t);
return t.get(timeout, timeUnit);
}
try {
Data data = call(new Callable<Data>() {
public Data call() throws Exception
{
// Open connection, get data here
return data;
}, 2, TimeUnit.SECONDS);
} catch (TimeoutException e) {
System.err.println("Data call timed-out");
}
하나의 옵션은 내가 생각 해본 적이 있어요하지만 실제로 Thread.stop를 때문에 스레드를 포기 같은 일 금액()는 I/O 작업을 차단하는 데 영향을주지 않습니다. – Dan