commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Wilson" <mart...@bright-interactive.com>
Subject Logging: SimpleLog not thread-safe
Date Fri, 06 Oct 2006 16:15:10 GMT
Hi,
 
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
time.
 
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
SimpleDateFormat(dateTimeFormat);
            }
catch(IllegalArgumentException e) {
                        dateFormatter = new
SimpleDateFormat(DEFAULT_DATE_TIME_FORMAT);
            }  
 
Is anyone available who could make this change?
 
Thanks, 
Martin
___________

Martin Wilson
martinw@bright-interactive.com

Bright Interactive: successfully delivering interactive websites and
business applications
 <http://www.bright-interactive.com/> http://www.bright-interactive.com
0870 240 6520
 

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