From: SourceForge.net <no...@so...> - 2006-08-08 10:10:36
|
Bugs item #1536558, was opened at 2006-08-08 10:10 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=115494&aid=1536558&group_id=15494 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: General Group: 1.0.x Status: Open Resolution: None Priority: 5 Submitted By: Colin Crist (colincrist) Assigned to: Nobody/Anonymous (nobody) Summary: RegularTimePeriond not thread safe Initial Comment: RegularTimePeriod.java (1.6.2.1) has a static Calendar. I have seem this cause problems if if data is placed into two TimeSeries concurrently - Dates can get created with incorrect values and other weirdness caused by Calendar not being thread safe. I have worked around the problem by changing the Calendar to being a ThreadLocal (I guess Calendar.getInstance returns a new Calendar each time...) public static final ThreadLocal WORKING_CALENDAR_TL = new ThreadLocal () ; public static Calendar getWorkingCalendar() { if (WORKING_CALENDAR_TL.get() == null) { WORKING_CALENDAR_TL.set(Calendar.getInstance(DEFAULT_TIME_ZONE)) ; } return (Calendar) WORKING_CALENDAR_TL.get() ; } Access to the calendar in the rest of the class is now via this getter. It works fine except you will leak Calendars when threads terminate. A better solution may be to place the Calendars in an LRUMap with some reasonable fixed upper limit. Regards, Colin. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=115494&aid=1536558&group_id=15494 |