At the SJSU Users Group Meeting


Last week I enjoyed speaking at the SSJU users group meeting… Here are the slides I used.  Special thanks to Ben who helped keep me on track during… I couple of interesting conversations came out of that meeting:

  1. We talked a lot about double check locking and the singleton pattern.  How it works in the CLR (thanks the ECMA Standardization effort) and how it is broken in Java.   
  2. We talked about Ngen…  I could not do a better job than this: NGen Overview
  3. Finally I got a chance to do an impromptu RAD development of an application to select attendees to get the SWAG I brought… The key bit of code you need if you are ever in this situation:

   new Random (28).ToString()  

Overall, I really enjoyed it..   Thanks to Fletcher Johnson who arranged it for me.

Comments (2)

  1. Stephen Cohen says:

    There is another alternative … You can use Enterprise Services to host an instance of class which has a minimum pool = 1 and Max pool = 1.

    just a thought

    –Stephen

  2. Dan Golick says:

    Instead of:

    private static volatile Singleton _value;

    How about using a non volatile and using the Thread.VolatileRead method:

    public sealed class Singleton {

    private Singleton() {}

    private static Singleton _value;

    private static object syncRoot = new Object();

    public static Singleton Value

    {

    get

    {

    if (Thread.VolatileRead(_value) == null)

    {

    lock (syncRoot)

    {

    if (_value == null)

    {

    _value = new Singleton();

    } //end inner if

    } //end lock

    } //end outer if

    return _value;

    } //end get

    } //end Value

    } //end class

    This guarantees on the reader thread that we read through the cache and will see Singleton in the fully initialized state without paying the penalty where we don’t need it.

    We could even get trickier and make sure that this only happened the first time we tried to read value.