commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Emmanuel Bourg (Commented) (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (SANDBOX-408) CSVFormat describes itself as immutable, but it is not - in particular it is not thread-safe
Date Tue, 06 Mar 2012 23:05:58 GMT

    [ https://issues.apache.org/jira/browse/SANDBOX-408?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13223765#comment-13223765
] 

Emmanuel Bourg commented on SANDBOX-408:
----------------------------------------

CSVFormat doesn't claim to be thread safe, it's just immutable otherwise it would be possible
to modify the predefined formats (CSVFormat.DEFAULT, CSVFormat.EXCEL, etc).

Thread safety is not a goal, but it's still good to have. With the current implementation
it's impossible for an instance to be mutated after the reference is shared with another thread.
So I think it's impossible for another thread to see a different value.

The case can be described like this:
# Thread A creates a bean and set a non final, non volatile field
# Thread A shares this instance with Thread B (through a queue for example)

Question: Is it possible for Thread B to get the bean with the field not mutated?

My understanding is that it's not possible, because for sharing the instance with Thread B
the instance that may have been cached in Thread A memory must necessarily be copied in it's
current state into the main memory, and that's with the field mutated. So Thread B receives
the bean with the field properly initialized.

Is this correct?

                
> CSVFormat describes itself as immutable, but it is not - in particular it is not thread-safe
> --------------------------------------------------------------------------------------------
>
>                 Key: SANDBOX-408
>                 URL: https://issues.apache.org/jira/browse/SANDBOX-408
>             Project: Commons Sandbox
>          Issue Type: Bug
>          Components: CSV
>            Reporter: Sebb
>
> CSVFormat describes itself as immutable, but it is not @Immutable - the class fields
are all mutable.
> The methods that change the fields do so by creating a clone, and returning the changed
clone.
> So in a sense the class is immutable.
> However, the normal expectation is that @Immutable classes are @ThreadSafe.
> CSVFormat is not thread-safe, because the fields are not volatile, and the fields are
not written & read using a common lock.
> The comment needs to be clarified or removed.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message