You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-dev@jackrabbit.apache.org by Jukka Zitting <ju...@gmail.com> on 2014/03/13 22:14:46 UTC

Re: svn commit: r1577316 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/ChangeDispatcher.java

Hi,

On Thu, Mar 13, 2014 at 4:58 PM,  <md...@apache.org> wrote:
> OAK-1491: ObservationTest failure on Windows
> Declare member accessed from multiple threads as volatile

It would be better to synchronized the addObserver() method. Otherwise
there's a risk of a newly added observer seeing two or more commits
merged together. Consider the following interleaving of execution in
two threads, A and B:

B: commit(State1);
A: observer.contentChanged(root, null);
B: commit(State2);
A: observers.addObserver(observer);
B: commit(State3);

As a result the observer added in thread A would see State1 as the
initial state of the repository, and State3 as the result of the first
observed commit. By synchronizing the addObserver() method we can
ensure that no commit() call is completed while the observer is being
added.

BR,

Jukka Zitting

Re: svn commit: r1577316 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/ChangeDispatcher.java

Posted by Michael Dürig <md...@apache.org>.

On 13.3.14 10:14 , Jukka Zitting wrote:
>
> As a result the observer added in thread A would see State1 as the
> initial state of the repository, and State3 as the result of the first
> observed commit. By synchronizing the addObserver() method we can
> ensure that no commit() call is completed while the observer is being
> added.

Good point! Fixed at r1577326.

Michael