lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Federico Fissore <>
Subject Re: Immutable OpenBitSet?
Date Thu, 28 Apr 2011 07:08:27 GMT
Nader, John P, il 28/04/2011 00:24, ha scritto:
> Thanks.  Your project looks interesting.  We've got some duplicate home-grown stuff here
that is similar.
> As far as thread-safety, if one thread initializes an OpenBitSet's by setting one or
bits and then hands that off to another thread, the other thread may see partial results.

I see your point. As Uwe said, you can safe publish an object 
initialized by a static initializer.
 From Java Concurrency in Practice, page 52, you read

To publish an object safely, both the reference to the object and the 
object’s state must be made visible to other threads at the same time. A
properly constructed object can be safely published by:
• Initializing an object reference from a static initializer;
• Storing a reference to it into a volatile field or AtomicReference;
• Storing a reference to it into a final field of a properly constructed
object; or
• Storing a reference to it into a field that is properly guarded by a

The last point means that if your bitset cache is backed by a 
synchronized collection, the JVM will guarantee the safe publication 
even of a non-thread-safe objects


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message