Details
-
Type: Bug
-
Status: Closed
-
Priority: Default
-
Resolution: Fixed
-
Affects Version/s: 1.5.3
-
Fix Version/s: 1.6.0
-
Component/s: None
-
Labels:None
Description
In quickfix library there is class
UtcTimestampConverter
in last version 1.5.3 there is static varaible
private static HashMap<String, Long> dateCache
As I see, this varaible is used as cache:
private static Long getMillisForDay(String value) { String dateString = value.substring(0, 8); Long millis = dateCache.get(dateString); if (millis == null) { Calendar c = new GregorianCalendar(1970, 0, 1, 0, 0, 0); c.setTimeZone(SystemTime.UTC_TIMEZONE); int year = Integer.parseInt(value.substring(0, 4)); int month = Integer.parseInt(value.substring(4, 6)); int day = Integer.parseInt(value.substring(6, 8)); c.set(year, month - 1, day); millis = c.getTimeInMillis(); dateCache.put(dateString, c.getTimeInMillis()); } return millis; }
But if this code will be invoked from different threads(in my case it is so), then HashMap my become broken, => cuncurrent access and modification of hashmap.
Under high load I can reproduce this on my dev server.
I would suggest to replace HashMap with ConcurrentHashMap
private static ConcurrentHashMap<String, Long> dateCache = new ConcurrentHashMap<String, Long>();