Too many EventManager's?

From: Peter Karich (peatha..ahoo.de)
Date: Thu Mar 29 2007 - 17:10:22 EDT

  • Next message: Arturo Perez: "1.2.2 fetchFinished broken?"

    Hello!

    I profile my application with netbeans profiler.
    And I figured out that there are 12 (!) EventManager's DispatchThreads
    started.
    All are in the 'waiting' state.
    I have no problems with that :-)
    But could it be that this code is problematic:

    public static EventManager getDefaultManager() {
            if (defaultManager == null) {
                synchronized (EventManager.class) {
                    if (defaultManager == null) {
                        defaultManager = new EventManager(2);
                    }
                }
            }
            return defaultManager;
        }

    See the problems with double checked locking here:

    http://en.wikipedia.org/wiki/Double-checked_locking

    Particularly the section:
    "One of the dangers of using double-checked locking in J2SE 1.4 ..."

    A simple solution can be:

    private static EventManager defaultManager = new EventManager(2);
    public static EventManager getDefaultManager() {
            return defaultManager;
    }

    OR a full synchronized method.

    Peter.



    This archive was generated by hypermail 2.0.0 : Thu Mar 29 2007 - 16:11:52 EDT