commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Wilson" <>
Subject Logging: SimpleLog not thread-safe
Date Fri, 06 Oct 2006 16:15:10 GMT
I'm not sure if anyone else uses the SimpleLog class - anyway I've
noticed that SimpleLog.log is not thread-safe. The following code
(starting on line 282):
        if(showDateTime) {
            buf.append(dateFormatter.format(new Date()));
            buf.append(" ");
makes an unsynchronized call to dateFormatter.format. As dateFormatter
is an instance variable, and DateFormat.format is not thread-safe, this
will cause problems if more than one thread tried to log at the same
Solution: remove the dateFormatter instance variable and instantiate a
new DateFormat each time in the log method, e.g.
DateFormat dateFormatter = null;
            try {
                        dateFormatter = new
catch(IllegalArgumentException e) {
                        dateFormatter = new
Is anyone available who could make this change?

Martin Wilson

Bright Interactive: successfully delivering interactive websites and
business applications
0870 240 6520

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message