Skip to content

Commit

Permalink
added thread context at the beginning of the constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
ishita9 committed Oct 11, 2024
1 parent 7e44a3a commit 1dad022
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions java/edu/ucar/metviewer/db/mysql/MysqlDatabaseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ public class MysqlDatabaseManager extends DatabaseManager {

public MysqlDatabaseManager(DatabaseInfo databaseInfo, String password) {
super(databaseInfo);

// Add hostname to the ThreadContext for logging
try {
String hostName = InetAddress.getLocalHost().getHostName();
ThreadContext.put("hostName", hostName);
} 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 @@ -86,13 +92,6 @@ public MysqlDatabaseManager(DatabaseInfo databaseInfo, String password) {

dataSource = new DataSource();
dataSource.setPoolProperties(configurationToUse);

try {
String hostName = InetAddress.getLocalHost().getHostName();
ThreadContext.put("hostName", hostName);
} catch (Exception e) {
logger.error("Unable to fetch the hostname for logging context", e);
}

boolean updateGroups = false;
if (databaseInfo.getDbName() == null) {
Expand Down

0 comments on commit 1dad022

Please sign in to comment.