- priority: 5 --> 8
The issue located in: net.sf.infrared.collector.StatisticsRepository.java
Method:
--------------------------------------------------
private void addStatsToStatsMap(ApplicationStatistics stats, Map map) {
String applicationName = stats.getApplicationName();
String instanceId = stats.getInstanceId();
String statsKey = constructStatsKey(applicationName, instanceId);
synchronized (map) {
ApplicationStatistics appStats = (ApplicationStatistics) map.get(statsKey);
if (appStats == null) {
map.put(statsKey, stats);
} else {
appStats.merge(stats);
}
}
--------------------------------------------------
The problem is in "if" statement, in case if appStats is null you put in map ApplicatinStatistic which is passed in the function. This method is called from:
--------------------------------------------------
public void addStatistics(ApplicationStatistics stats) {
addStatsToStatsMap(stats, mapOfStatsSinceStartup);
addStatsToStatsMap(stats, mapOfStatsSinceLastPersist);
}
--------------------------------------------------
So when it called for the first time, both instance variables: "mapOfStatsSinceStartup" and "mapOfStatsSinceLastPersist" are empty and the same object stats put in both map.
After this if this method called again in a few time,merge operation performes on the same ApplicationStatistics object twice.
Suggested fix:
-------- code ------------------------------------
private void addStatsToStatsMap(ApplicationStatistics stats, Map map) {
String applicationName = stats.getApplicationName();
String instanceId = stats.getInstanceId();
String statsKey = constructStatsKey(applicationName, instanceId);
synchronized (map) {
ApplicationStatistics appStats = (ApplicationStatistics) map.get(statsKey);
if (appStats == null) {
ApplicationStatistics tmpStats = new ApplicationStatistics(applicationName,instanceId);
tmpStats.merge(stats);
map.put(statsKey, tmpStats);
} else {
appStats.merge(stats);
}
}
}
--------------------------------------------------
-------------
With the best wishes,
Alex Tsiunchick,
Lead Software Engineer,
Minsk, Belarus.
e-mail: AlexeyTsiunchik@mail.ru