commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <>
Subject [jira] Commented: (COMPRESS-60) ChangeSet does not synchronise whilst using the Iterator
Date Sat, 28 Mar 2009 13:51:50 GMT


Sebb commented on COMPRESS-60:

Depends on whether you want to make the class thread-safe or not.

Would one ever want to create the same ChangeSet and apply it to multiple archives in multiple
Probably not, and even if the class were thread-safe, sharing the same set of changes would
not work.
The first thread to perform() the ChangeSet would remove one or more of the entries.

In fact, ChangeSet is not even re-usable in a single thread, as perform empties the list of

There might be a use-case for making it re-usable - i.e. perform the same changes on multiple

In which case, perfom() should operate on a copy of the Set.

It should then be possible to use the class in multiple threads, so long as:
+ other threads only used perform()
+ the creator thread did not change the instance after calling start() on the worker threads.

Or I suppose one could create a new thread-safe (perhaps immutable)  "performer" class once
a change set had been set up.
I.e. separate the creation of the ChangeSet from its application.

> ChangeSet does not synchronise whilst using the Iterator
> --------------------------------------------------------
>                 Key: COMPRESS-60
>                 URL:
>             Project: Commons Compress
>          Issue Type: Bug
>            Reporter: Sebb
>             Fix For: 1.0
> ChangeSet does not synchronize whilst using the Iterator on the Set "changes" which is
a synchronizedSet.
> The Javadoc for Collections.synchronizedSet says: "
> ...
> It is imperative that the user manually synchronize on the returned set when iterating
over it:
> ...
> Failure to follow this advice may result in non-deterministic behavior."
> This affects the add() and perfom() methods.
> Also, the asSet() method returns a reference to the Set.  This method does not seem to
be used at present, so perhaps could be removed.
> Otherwise, it should either return a copy of the set, or the Javadoc should point out
that any iteration over the set must synchronize on the set.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message