Skip to content
Snippets Groups Projects
Commit a2809d70 authored by brinn's avatar brinn
Browse files

fix: unsafe usage of SimpleDateFormat object in different threads

SVN: 6293
parent 0ed13791
No related branches found
No related tags found
No related merge requests found
...@@ -18,7 +18,6 @@ package ch.systemsx.cisd.bds; ...@@ -18,7 +18,6 @@ package ch.systemsx.cisd.bds;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.concurrent.atomic.AtomicReference;
/** /**
* Some constants used inside the <i>BDS</i> library * Some constants used inside the <i>BDS</i> library
...@@ -35,8 +34,16 @@ public final class Constants ...@@ -35,8 +34,16 @@ public final class Constants
public final static char PATH_SEPARATOR = '/'; public final static char PATH_SEPARATOR = '/';
/** The uniformly date format used. */ /** The uniformly date format used. */
public static final AtomicReference<DateFormat> DATE_FORMAT = // Note that DateFormats objects are not thread-safe.
new AtomicReference<DateFormat>(new SimpleDateFormat(DATE_FORMAT_PATTERN)); public static final ThreadLocal<DateFormat> DATE_FORMAT =
new ThreadLocal<DateFormat>()
{
@Override
protected DateFormat initialValue()
{
return new SimpleDateFormat(DATE_FORMAT_PATTERN);
}
};
private Constants() private Constants()
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment