in core/src/main/java/org/apache/calcite/avatica/remote/KerberosConnection.java [192:234]
public void stopRenewalThread() {
if (null != renewalTask && null != renewalThread) {
LOG.debug("Informing RenewalTask to gracefully stop and interrupting the renewal thread.");
renewalTask.asyncStop();
long now = System.currentTimeMillis();
long until = now + 5000;
while (now < until) {
if (renewalThread.isAlive()) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
now = System.currentTimeMillis();
} else {
break;
}
}
if (renewalThread.isAlive()) {
LOG.warn("Renewal thread failed to gracefully stop, interrupting it");
renewalThread.interrupt();
try {
renewalThread.join(5000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
// What more could we do?
if (renewalThread.isAlive()) {
LOG.warn("Renewal thread failed to gracefully and ungracefully stop, proceeding.");
}
renewalTask = null;
renewalThread = null;
} else {
LOG.warn("Renewal thread was never started or already stopped.");
}
}