cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Karich <peat...@yahoo.de>
Subject Too many EventManager's?
Date Thu, 29 Mar 2007 21:10:22 GMT
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.

Mime
View raw message