Issue 12001
HttpUtils has illegal use of SimpleDateFormat in a non threadsafe manner
12001
Reporter: trobertson
Assignee: mdoering
Type: Bug
Summary: HttpUtils has illegal use of SimpleDateFormat in a non threadsafe manner
Priority: Critical
Resolution: Fixed
Status: Closed
Created: 2012-10-10 10:26:05.931
Updated: 2013-12-06 12:06:30.824
Resolved: 2012-11-21 00:03:39.562
Description: SimpleDateFormat is not threadsafe. From the API:
"Date formats are not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally."
HttpUtil however has:
static final SimpleDateFormat DATE_FORMAT_RFC2616 =
new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);
This needs to be replaced with something more along the lines of:
static SimpleDateFormat getDateFormatRFC2616() {
new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);
}
Or just have the pattern:
static final String DATE_FORMAT_RFC2616 = "EEE, dd MMM yyyy HH:mm:ss Z";
And any existing reference to that be replaced with:
new SimpleDateFormat(HttpUtil.DATE_FORMAT_RFC2616);
Alternatively, use org.apache.commons.lang3.time.FastDateFormat which is a direct replacement and is thread safe]]>
Author: lfrancke@gbif.org
Comment: Good find! I however suggest avoiding the commons lang version. There have been a few (at least one :) ) blog posts comparing the performance and it was basically as fast to just create a new SimpleDateFormat and avoid introducing another dependency on commons-lang IIRC.
Created: 2012-10-10 10:32:48.489
Updated: 2012-10-10 10:32:48.489
Author: mdoering@gbif.org
Created: 2012-11-21 00:03:39.588
Updated: 2012-11-21 00:03:39.588
http://code.google.com/p/gbif-common-resources/source/detail?r=1204
http://code.google.com/p/gbif-common-resources/source/detail?r=1205