JDK 8 RFC 6470700: Math.random() / Math.initRNG() uses "double checked locking"

Brian Burkhalter brian.burkhalter at oracle.com
Thu Aug 22 00:24:38 UTC 2013


On Aug 21, 2013, at 5:01 PM, David M. Lloyd wrote:

> I don't think you'd want to introduce the overhead of synchronization here.

No, I don't. My example code was just that.

> It may be better in this case to use this kind of lazy init pattern:
> 
>    static final class Holder {
>        static final Random RNG = new Random();
>    }
> 
>    public static double random() {
>        return Holder.RNG.nextDouble();
>    }

Thanks for the cleaner suggestion.

Brian


More information about the core-libs-dev mailing list