Fix gettimezone performanceissue (#1607)

* [(release_3_7_SSE)] cache timezone since timezone.gettimezone is static synchronized and performs poorly

* [(fixgettimezoneperformanceissue)] fiximport
This commit is contained in:
abrsystematic 2020-10-09 17:51:50 +02:00 committed by GitHub
parent d5b533c73c
commit cad3ba5a66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -32,6 +32,8 @@ import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import static org.apache.commons.lang3.StringUtils.isBlank;
@ -39,6 +41,8 @@ public abstract class BaseDateTimeDt extends BasePrimitive<Date> {
static final long NANOS_PER_MILLIS = 1000000L;
static final long NANOS_PER_SECOND = 1000000000L;
private static final Map<String, TimeZone> timezoneCache = new ConcurrentHashMap<>();
private static final FastDateFormat ourHumanDateFormat = FastDateFormat.getDateInstance(FastDateFormat.MEDIUM);
private static final FastDateFormat ourHumanDateTimeFormat = FastDateFormat.getDateTimeInstance(FastDateFormat.MEDIUM, FastDateFormat.MEDIUM);
private static final FastDateFormat ourXmlDateTimeFormat = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss");
@ -575,12 +579,17 @@ public abstract class BaseDateTimeDt extends BasePrimitive<Date> {
parseInt(theWholeValue, theValue.substring(1, 3), 0, 23);
parseInt(theWholeValue, theValue.substring(4, 6), 0, 59);
clearTimeZone();
setTimeZone(TimeZone.getTimeZone("GMT" + theValue));
setTimeZone(getTimeZone(theValue));
}
return this;
}
private TimeZone getTimeZone(String offset) {
return timezoneCache.computeIfAbsent(offset, (offsetLocal) ->
TimeZone.getTimeZone("GMT" + offsetLocal));
}
public BaseDateTimeDt setTimeZone(TimeZone theTimeZone) {
myTimeZone = theTimeZone;
updateStringValue();