If you cannot get the admins to provide your app with a near-infinite
ticket lifetime, you need to instead loop the login process via a
daemon thread, such as via this thread snippet as an example:
private void runLoginAndRenewalThread(final Configuration conf) throws
IOException {
// Do a blocking login first
SecurityUtil.login(conf, KEYTAB_CONF, KEYTAB_USER);
// Spawn the relogin thread next
Thread reloginThread = new Thread() {
@Override
public void run() {
while (true) {
try {
SecurityUtil.login(conf, KEYTAB_CONF, KEYTAB_USER);
Thread.sleep(ELEVEN_MINUTES);
} catch (IOException e) {
e.printStackTrace();
interrupt();
} catch (InterruptedException e) {
e.printStackTrace();
interrupt();
}
}
}
};
reloginThread.setDaemon(true);
reloginThread.start();
}