From a2809d70b2f3c67e362f22fb53f4e2747cebb9da Mon Sep 17 00:00:00 2001 From: brinn <brinn> Date: Sat, 24 May 2008 11:24:54 +0000 Subject: [PATCH] fix: unsafe usage of SimpleDateFormat object in different threads SVN: 6293 --- bds/source/java/ch/systemsx/cisd/bds/Constants.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bds/source/java/ch/systemsx/cisd/bds/Constants.java b/bds/source/java/ch/systemsx/cisd/bds/Constants.java index ff63810174f..650dbd33f11 100644 --- a/bds/source/java/ch/systemsx/cisd/bds/Constants.java +++ b/bds/source/java/ch/systemsx/cisd/bds/Constants.java @@ -18,7 +18,6 @@ package ch.systemsx.cisd.bds; import java.text.DateFormat; import java.text.SimpleDateFormat; -import java.util.concurrent.atomic.AtomicReference; /** * Some constants used inside the <i>BDS</i> library @@ -35,8 +34,16 @@ public final class Constants public final static char PATH_SEPARATOR = '/'; /** The uniformly date format used. */ - public static final AtomicReference<DateFormat> DATE_FORMAT = - new AtomicReference<DateFormat>(new SimpleDateFormat(DATE_FORMAT_PATTERN)); + // Note that DateFormats objects are not thread-safe. + public static final ThreadLocal<DateFormat> DATE_FORMAT = + new ThreadLocal<DateFormat>() + { + @Override + protected DateFormat initialValue() + { + return new SimpleDateFormat(DATE_FORMAT_PATTERN); + } + }; private Constants() { -- GitLab