destroy() shuts down the taskScheduler

Issue gh-15735
This commit is contained in:
Rob Winch 2024-10-01 08:50:41 -05:00
parent 50cc36d53e
commit 4f328c9503
2 changed files with 11 additions and 2 deletions

View File

@ -30,6 +30,7 @@ import java.util.function.Function;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.jdbc.core.ArgumentPreparedStatementSetter; import org.springframework.jdbc.core.ArgumentPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.PreparedStatementSetter; import org.springframework.jdbc.core.PreparedStatementSetter;
@ -55,7 +56,7 @@ import org.springframework.util.StringUtils;
* @author Max Batischev * @author Max Batischev
* @since 6.4 * @since 6.4
*/ */
public final class JdbcOneTimeTokenService implements OneTimeTokenService { public final class JdbcOneTimeTokenService implements OneTimeTokenService, DisposableBean {
private final Log logger = LogFactory.getLog(getClass()); private final Log logger = LogFactory.getLog(getClass());
@ -187,6 +188,13 @@ public final class JdbcOneTimeTokenService implements OneTimeTokenService {
this.logger.debug("Cleaned up " + deletedCount + " expired tokens"); this.logger.debug("Cleaned up " + deletedCount + " expired tokens");
} }
@Override
public void destroy() throws Exception {
if (this.taskScheduler != null) {
this.taskScheduler.shutdown();
}
}
/** /**
* Sets the {@link Clock} used when generating one-time token and checking token * Sets the {@link Clock} used when generating one-time token and checking token
* expiry. * expiry.

View File

@ -68,8 +68,9 @@ public class JdbcOneTimeTokenServiceTests {
} }
@AfterEach @AfterEach
public void tearDown() { public void tearDown() throws Exception {
this.db.shutdown(); this.db.shutdown();
this.oneTimeTokenService.destroy();
} }
private static EmbeddedDatabase createDb() { private static EmbeddedDatabase createDb() {