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

Ceki Gulcu (JIRA) noreply-jira at qos.ch
Mon Jun 15 15:34:10 CEST 2009


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

Ceki Gulcu edited comment on LBCLASSIC-36 at 6/15/09 3:33 PM:
--------------------------------------------------------------

> 1. There is no reason to synchronize in the Joda test. DateTimeFormatter should be declared external to the 
> method and the synchronization should be removed since DateTimeFormatter is thread safe. 

I believe that to be incorrect. While Joda's DateTimeFormatter may be thread safe, assignment to a long is not an atomic operation in Java. The synchronized block exist to protect the "cache" not DateTimeFormatter.

Just read modified DateFormatPerfTest you provided, I see that you already protected the "cache." In that case, there is indeed no need to protect DateTimeFormatter. Sorry for jumping to conclusions.

      was (Author: noreply.ceki at qos.ch):
    > 1. There is no reason to synchronize in the Joda test. DateTimeFormatter should be declared external to the 
> method and the synchronization should be removed since DateTimeFormatter is thread safe. 

I beleive that to be incorrect. While Joda's DateTimeFormatter may be thread safe, assignment to a long is not an atomic operation in Java. The synchronized block exist to protect the "cache" not 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, DateFormatPerfTest.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