From a4e5e7a0c5f4637ced2d2805dcacb81da369eb12 Mon Sep 17 00:00:00 2001 From: ishitas Date: Fri, 11 Oct 2024 00:37:26 +0000 Subject: [PATCH] Changed ThreadContext placement --- .../metviewer/db/mysql/MysqlDatabaseManager.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/java/edu/ucar/metviewer/db/mysql/MysqlDatabaseManager.java b/java/edu/ucar/metviewer/db/mysql/MysqlDatabaseManager.java index 4c017f17..bf90cd6a 100644 --- a/java/edu/ucar/metviewer/db/mysql/MysqlDatabaseManager.java +++ b/java/edu/ucar/metviewer/db/mysql/MysqlDatabaseManager.java @@ -59,12 +59,7 @@ public class MysqlDatabaseManager extends DatabaseManager { public MysqlDatabaseManager(DatabaseInfo databaseInfo, String password) { super(databaseInfo); // Set the hostname in ThreadContext for logging purposes - try { - String hostName = InetAddress.getLocalHost().getHostName(); - ThreadContext.put("hostName", hostName); // Add hostname to the ThreadContext - } catch (Exception e) { - logger.error("Unable to fetch the hostname for logging context", e); - } + String jdbcUrl = getJdbcUrl(databaseInfo.getHost(), databaseInfo.getDbName()); PoolConfiguration configurationToUse = new PoolProperties(); configurationToUse.setUrl(jdbcUrl); @@ -100,8 +95,14 @@ public MysqlDatabaseManager(DatabaseInfo databaseInfo, String password) { updateGroups = true; } initDBList(updateGroups); + try { + String hostName = InetAddress.getLocalHost().getHostName(); + ThreadContext.put("hostName", hostName); // Add hostname to the ThreadContext + } catch (Exception e) { + logger.error("Unable to fetch the hostname for logging context", e); + } } - + public synchronized String formatDate(Date date) { return DATE_FORMAT.format(date.getTime()); }