[concurrency-interest] Impossible Exception?

Sam Berlin sberlin at gmail.com
Mon Jan 14 12:15:42 EST 2008


This would defeat the 'singleton' purpose. :-)

Thanks very much to everyone for their tips & pointers.

We'll likely fix this one by catching exceptions thrown from
createObject and rethrowing a new exception upon later gets.

Sam

On 1/14/08, Joe Bowbeer <joe.bowbeer at gmail.com> wrote:
> Err..
>
> constructing could/should be reset if obj is *not* created:
>
>   constructing = true;
>   try {
>     obj = createObject();
>   } finally {
>     if (obj == null)
>       constructing = false;
>   }
>
> Or simply:
>
>   constructing = true;
>   try {
>     obj = createObject();
>   } finally {
>     constructing = false;
>
>   }
>
>
> On Jan 14, 2008 8:44 AM, Joe Bowbeer wrote:
> > constructing could/should be reset if obj is not created:
> >
> >   constructing = true;
> >   try {
> >     obj = createObject();
> >   } finally {
> >     if (obj != null)
> >       constructing = false;
> >   }
> >
> > Though I suspect constructing was only added was to investigate this case
> of the missing exception...
> >
> >
> >
> >
> >
> > On Jan 14, 2008 7:25 AM, Thomas Hawtin <Thomas.Hawtin at sun.com> wrote:
> >
> > >
> > > Kevin Condon wrote:
> > > >
> > > > Isn't the statement "constructing = false;" missing after
> > > > createObject() is invoked?  All get() calls after the first one will
> > > > throw the exception.
> > >
> > > No, the test "obj == null" should be false after a successful
> > > initialisation and therefore "constructing" will not be read.
> > >
> > > Tom Hawtin
> > >
> > >
> > > > On Jan 13, 2008 8:44 PM,  <
> concurrency-interest-request at cs.oswego.edu> wrote:
> > > >> ---------- Forwarded message ----------
> > > >> From: "Sam Berlin" < sberlin at gmail.com>
> > >
> > > >> [...]
> > > >>         if(obj == null) {
> > > >>             if(constructing)
> > > >>                 throw new
> IllegalStateException("constructing again!");
> > > >>             constructing = true;
> > > >>             obj = createObject();
> > > >>         }
> > >
> >
> >
>
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
>
>


More information about the Concurrency-interest mailing list