lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Trejkaz <>
Subject Re: Immutable OpenBitSet?
Date Thu, 28 Apr 2011 12:44:56 GMT
On Thu, Apr 28, 2011 at 6:13 PM, Uwe Schindler <> wrote:
> In general a *newly* created object that was not yet seen by any other
> thread is always safe. This is why I said, set all bits in the ctor. This is
> easy to understand: Before the ctor returns, the object's contents and all
> references like arrays are not seen by any other thread (that's guaranteed).

Section 17.5 of the JLS gives the following example:

    class FinalFieldExample {
      final int x;
      int y;
      static FinalFieldExample f;
      public FinalFieldExample() {
        x = 3;
        y = 4;
      static void writer() {
        f = new FinalFieldExample();
      static void reader() {
        if (f != null) {
          int i = f.x; // guaranteed to see 3
          int j = f.y; // could see 0

Essentially, there is no guarantee that the work in the constructor
has been completed when another thread gets a reference to the object.
 To make the guarantee, use the final keyword.

It seems like this contradicts the claim above, but maybe I'm missing something.


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

View raw message