dev@glassfish.java.net

Re: Findbugs exception

From: John Wells <john.wells_at_oracle.com>
Date: Fri, 19 Apr 2013 08:18:29 -0400

So, it looks like, according to that article, that making controller
volatile will fix this, right?

On 4/19/2013 8:08 AM, Bobby Bissett wrote:
> On Fri, Apr 19, 2013 at 6:42 AM, John Wells <john.wells_at_oracle.com
> <mailto:john.wells_at_oracle.com>> wrote:
>
> [...]
> This is the only thing in the file that ever sets the controller
> variable, and the variable never becomes unset. To me this is
> valid java...
>
>
> It's "valid" I guess, but it won't work when you want it to. The usual
> answer to this question is:
>
> http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
> <http://www.cs.umd.edu/%7Epugh/java/memoryModel/DoubleCheckedLocking.html>
>
> (Very short summary: non-null doesn't mean initialized correctly.)
>
> If you really want to use lazy initialization, and you really really
> don't want to synchronize on the method, try the lazy initialization
> holder class method instead. Lots of examples online.
>
> Cheers,
> Bobby
>