Skip to content

Commit

Permalink
Changed ThreadContext placement
Browse files Browse the repository at this point in the history
  • Loading branch information
ishita9 committed Oct 11, 2024
1 parent 8228cc9 commit a4e5e7a
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions java/edu/ucar/metviewer/db/mysql/MysqlDatabaseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit a4e5e7a

Please sign in to comment.