diff --git a/dspace-api/src/main/java/org/dspace/core/HibernateDBConnection.java b/dspace-api/src/main/java/org/dspace/core/HibernateDBConnection.java index 04334b8a1a3b..f8c620380d5f 100644 --- a/dspace-api/src/main/java/org/dspace/core/HibernateDBConnection.java +++ b/dspace-api/src/main/java/org/dspace/core/HibernateDBConnection.java @@ -10,7 +10,6 @@ import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.SQLException; -import javax.annotation.PostConstruct; import javax.sql.DataSource; import org.apache.logging.log4j.LogManager; @@ -36,6 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.orm.hibernate5.SessionFactoryUtils; +import org.springframework.scheduling.annotation.Scheduled; /** * Hibernate implementation of the DBConnection. @@ -108,22 +108,12 @@ protected Transaction getTransaction() { return sessionFactory.getCurrentSession().getTransaction(); } -// @PostConstruct -// public void startConnectionLogging() { -// // Start a thread to log active connection metrics periodically -// new Thread(() -> { -// while (true) { -// try { -// logHibernateStatistics(); -// logDatabaseMetaData(); -// Thread.sleep(10000); // Log every 10 seconds -// } catch (InterruptedException e) { -// Thread.currentThread().interrupt(); -// break; -// } -// } -// }).start(); -// } + // This method will run every 10 seconds + @Scheduled(fixedRate = 10000) // Fixed rate in milliseconds + public void logConnectionMetrics() { + logHibernateStatistics(); + logDatabaseMetaData(); + } /** * Check if Hibernate Session is still "alive" / open. An open Session may or may not have an open Transaction