Index: logback-classic/src/test/java/ch/qos/logback/classic/issue/lbclassic36/SelectiveDateFormattingRunnable.java =================================================================== --- logback-classic/src/test/java/ch/qos/logback/classic/issue/lbclassic36/SelectiveDateFormattingRunnable.java (revision 2293) +++ logback-classic/src/test/java/ch/qos/logback/classic/issue/lbclassic36/SelectiveDateFormattingRunnable.java Wed Jun 17 12:39:31 CEST 2009 @@ -1,6 +1,8 @@ package ch.qos.logback.classic.issue.lbclassic36; import java.text.SimpleDateFormat; +import java.util.concurrent.atomic.AtomicLong; + import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; @@ -22,7 +24,7 @@ } FormattingModel model; - static long CACHE = 0; + static AtomicLong CACHE = new AtomicLong(); static SimpleDateFormat SDF = new SimpleDateFormat(ISO8601_PATTERN); static final DateTimeFormatter JODA = DateTimeFormat @@ -46,10 +48,9 @@ void sdfRun() { for (;;) { - synchronized (SDF) { - long now = System.currentTimeMillis(); + long now = System.currentTimeMillis(); - if (CACHE != now) { - CACHE = now; + if(isCacheStale(now)) { + synchronized (SDF) { SDF.format(now); } } @@ -74,12 +75,9 @@ } private static boolean isCacheStale(long now) { - synchronized (JODA) { - if (CACHE != now) { - CACHE = now; + if(CACHE.getAndSet(now) != now) { - return true; - } + return true; + } - } return false; }