[logback-dev] [JIRA] Commented: (LBCLASSIC-36) Synchronization of SimpleDateFormat object in DateConverter

Ralph Goers (JIRA) noreply-jira at qos.ch
Sun Jun 14 03:06:12 CEST 2009


    [ http://jira.qos.ch/browse/LBCLASSIC-36?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=11174#action_11174 ] 

Ralph Goers commented on LBCLASSIC-36:
--------------------------------------

Since you asked...

I created a test to compare Joda Time to Simple Date Format. The results I get on my Mac are:

Running TestDateFormat
Raw - JDK: 3673 ns Joda: 2587 ns - Difference: 29.56711%
Synchronized DateFormat: 0.4640 seconds
Unsynchronized DateFormat: 2.2500 seconds
ThreadLocal DateFormat: 0.2224 seconds
Joda DateTimeFormatter: 0.1631 seconds
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.871 sec

The raw test just performs a date format 100,000 times in a loop on a single thread.
The synchronized test behaves like Logback currently does, synchronizing calls to format the date.
The unsynchronized uses a new SimpleDateTime for each invocation.
The threadlocal test creates a SimpleDateFormat for each thread.
The joda test uses Joda Time's DateTimeFormatter.



> Synchronization of SimpleDateFormat object in DateConverter
> -----------------------------------------------------------
>
>                 Key: LBCLASSIC-36
>                 URL: http://jira.qos.ch/browse/LBCLASSIC-36
>             Project: logback-classic
>          Issue Type: Bug
>          Components: Other
>    Affects Versions: unspecified
>         Environment: Operating System: All
> Platform: All
>            Reporter: Anders Hammar
>            Assignee: Ceki Gulcu
>         Attachments: DateConverter_patch.java, dateformattest.zip
>
>
> According to the API documentation of SimpleDateFormat, date formats are not synchronized and it is recommended to create separate format instances for each thread.
> However, a possibly simpler (mer efficient) solution would be to synchronize on the SimpleDateFormat object in the convert() method to prevent two threads to access it concurrently.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the logback-dev mailing list