Skip to content

Instantly share code, notes, and snippets.

@sh0seo
Created August 14, 2019 00:23
Show Gist options
  • Save sh0seo/64f5923cf1107423ee69cac5ee049f0b to your computer and use it in GitHub Desktop.
Save sh0seo/64f5923cf1107423ee69cac5ee049f0b to your computer and use it in GitHub Desktop.
private int getAndSetNetworkTimeout(Connection connection, long timeoutMs) {
if (this.isNetworkTimeoutSupported != 0) {
try {
int originalTimeout = connection.getNetworkTimeout();
connection.setNetworkTimeout(this.netTimeoutExecutor, (int)timeoutMs);
this.isNetworkTimeoutSupported = 1;
return originalTimeout;
} catch (AbstractMethodError | Exception var5) {
if (this.isNetworkTimeoutSupported == -1) {
this.isNetworkTimeoutSupported = 0;
this.logger.info("{} - Driver does not support get/set network timeout for connections. ({})", this.poolName, var5.getMessage());
if (this.validationTimeout < TimeUnit.SECONDS.toMillis(1L)) {
this.logger.warn("{} - A validationTimeout of less than 1 second cannot be honored on drivers without setNetworkTimeout() support.", this.poolName);
} else if (this.validationTimeout % TimeUnit.SECONDS.toMillis(1L) != 0L) {
this.logger.warn("{} - A validationTimeout with fractional second granularity cannot be honored on drivers without setNetworkTimeout() support.", this.poolName);
}
}
}
}
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment