From d4c79e06d8989cc731bdca9c471217f7a27f6b7c Mon Sep 17 00:00:00 2001 From: anhefti Date: Thu, 4 Mar 2021 13:50:40 +0100 Subject: [PATCH] code cleanup --- .../session/impl/AsyncBatchEventSaveStrategy.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/AsyncBatchEventSaveStrategy.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/AsyncBatchEventSaveStrategy.java index d1936134..31e33f05 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/AsyncBatchEventSaveStrategy.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/AsyncBatchEventSaveStrategy.java @@ -138,13 +138,14 @@ public class AsyncBatchEventSaveStrategy implements EventHandlingStrategy { SEBServerInit.INIT_LOGGER.info("> Worker Thread {} running", Thread.currentThread()); final Collection events = new ArrayList<>(); + @SuppressWarnings("resource") final SqlSessionTemplate sqlSessionTemplate = new SqlSessionTemplate( this.sqlSessionFactory, ExecutorType.BATCH); final ClientEventRecordMapper clientEventMapper = sqlSessionTemplate.getMapper( ClientEventRecordMapper.class); - long sleepTime = 100; + long sleepTime = MIN_SLEEP_TIME; try { while (this.workersRunning) { @@ -175,7 +176,13 @@ public class AsyncBatchEventSaveStrategy implements EventHandlingStrategy { } } } finally { - sqlSessionTemplate.close(); + try { + sqlSessionTemplate.destroy(); + } catch (final Exception e) { + log.error("Failed to close and destroy the SqlSessionTemplate for this thread: {}", + Thread.currentThread(), + e); + } log.debug("Worker Thread {} stopped", Thread.currentThread()); } };