From 5359e744750d25027561f5e404f2b08bbb9289c8 Mon Sep 17 00:00:00 2001 From: TimeInvestor Date: Fri, 4 Mar 2016 18:51:50 +0800 Subject: [PATCH] Only have one Hibernate SessionFactory I think this is the root cause of this plugin causing too many DB connections especially when one has many Jenkins slaves. I have tested this change on local setting. --- .../plugins/audit2db/internal/data/HibernateUtil.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jenkins/plugins/audit2db/internal/data/HibernateUtil.java b/src/main/java/org/jenkins/plugins/audit2db/internal/data/HibernateUtil.java index 71c15c2..fd12056 100644 --- a/src/main/java/org/jenkins/plugins/audit2db/internal/data/HibernateUtil.java +++ b/src/main/java/org/jenkins/plugins/audit2db/internal/data/HibernateUtil.java @@ -25,7 +25,9 @@ */ public class HibernateUtil { private final static Logger LOGGER = Logger.getLogger(HibernateUtil.class.getName()); - + + private static SessionFactory retval = null; + private static Configuration getConfig(final Properties extraProperties) throws HibernateException { LOGGER.log(Level.INFO, Messages.HibernateUtil_LoadConfig()); final Configuration config = new AnnotationConfiguration().configure(); @@ -38,7 +40,9 @@ private static Configuration getConfig(final Properties extraProperties) throws } public static SessionFactory getSessionFactory(final Properties extraProperties) { - SessionFactory retval = null; + if (retval != null) { + return retval; + } try { // Load base configuration from hibernate.cfg.xml