From f08919a82938945419b8bfb74c1d72cb1f0a5845 Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Sat, 22 Feb 2014 09:25:52 -0500 Subject: [PATCH] made initialize and cleanup synchronized so we can avoid un-needed duplicate initialization/cleanup Former-commit-id: 061d6a1a5c56806ea7c23d2599a6c6f7df1dae58 --- .../data/nvdcve/ConnectionFactory.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nvdcve/ConnectionFactory.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nvdcve/ConnectionFactory.java index d5a154bb5..90d523803 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nvdcve/ConnectionFactory.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nvdcve/ConnectionFactory.java @@ -80,7 +80,12 @@ public final class ConnectionFactory { * * @throws DatabaseException thrown if we are unable to connect to the database */ - public static void initialize() throws DatabaseException { + public static synchronized void initialize() throws DatabaseException { + //this only needs to be called once. + if (connectionString != null) { + return; + } + //load the driver if necessary final String driverName = Settings.getString(Settings.KEYS.DB_DRIVER_NAME, ""); if (!driverName.isEmpty()) { //likely need to load the correct driver @@ -173,7 +178,7 @@ public final class ConnectionFactory { /** * Cleans up resources and unloads any registered database drivers. */ - public static void cleanup() { + public static synchronized void cleanup() { if (driver != null) { try { DriverManager.deregisterDriver(driver); @@ -182,6 +187,9 @@ public final class ConnectionFactory { } driver = null; } + connectionString = null; + userName = null; + password = null; } /**