change
This commit is contained in:
parent
6f5ed79457
commit
df3d268176
|
@ -4,7 +4,7 @@ import java.sql.*;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
public abstract class AbstractConnection extends WrapperImpl implements Connection {
|
public abstract class AbstractConnection extends WrapperImpl implements Connection {
|
||||||
|
|
||||||
|
@ -291,19 +291,37 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid(int timeout) throws SQLException {
|
public boolean isValid(int timeout) throws SQLException {
|
||||||
|
//true if the connection is valid, false otherwise
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
return false;
|
return false;
|
||||||
if (timeout < 0)
|
if (timeout < 0) //SQLException - if the value supplied for timeout is less then 0
|
||||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
|
||||||
|
|
||||||
int status;
|
ExecutorService executor = Executors.newCachedThreadPool();
|
||||||
try (Statement stmt = createStatement()) {
|
Future<Boolean> future = executor.submit(() -> {
|
||||||
ResultSet resultSet = stmt.executeQuery("select server_status()");
|
int status;
|
||||||
resultSet.next();
|
try (Statement stmt = createStatement()) {
|
||||||
status = resultSet.getInt("server_status()");
|
ResultSet resultSet = stmt.executeQuery("select server_status()");
|
||||||
resultSet.close();
|
resultSet.next();
|
||||||
|
status = resultSet.getInt("server_status()");
|
||||||
|
resultSet.close();
|
||||||
|
}
|
||||||
|
return status == 1 ? true : false;
|
||||||
|
});
|
||||||
|
|
||||||
|
boolean status = false;
|
||||||
|
try {
|
||||||
|
status = future.get(timeout, TimeUnit.MILLISECONDS);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (TimeoutException e) {
|
||||||
|
future.cancel(true);
|
||||||
|
} finally {
|
||||||
|
executor.shutdownNow();
|
||||||
}
|
}
|
||||||
return status == 1 ? true : false;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue