Re: Too many EventManager's?

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Fri Mar 30 2007 - 09:20:19 EDT

  • Next message: Marc Gabriel-Willem: "RE: Cayenne -- Apache automatic deploy problem"

    Looking more into this, it looks like there is some legacy code that
    results in so many dispatch queue threads being instantiated:

    * map package uses static default EM (2 threads)
    * each Configuration instance uses its own EM (+5 threads per
    Configuration)

    Some cleanup is due here. The first case is really legacy stuff used
    by the Modeler. No need to carry it over in runtime. The second case
    can be improved. First CAY-610 needs to be fixed [1], second, we may
    implement a smarter dispatch thread pooling, shutting down unused
    threads.

    To summarize, there is nothing critically broken in the current
    implementation, but cleaning it up is desirable at some point. BTW, I
    changed shared EM instance to be 'volatile', but I don't think it
    caused us any grief to date.

    Andrus

    [1] https://issues.apache.org/cayenne/browse/CAY-610

    On Mar 30, 2007, at 4:40 PM, Andrus Adamchik wrote:

    > Interesting. Didn't know it was a known problem with java 1.4.
    >
    > Lazy initialization was used exactly because we don't want dispatch
    > threads to start unless they are needed. So ... per Wikipedia
    > article this is a legacy JDK problem and going forward we should
    > simply be using "volatile" keyword, which I think we should.
    >
    > Andrus
    >
    >
    > On Mar 30, 2007, at 1:10 AM, Peter Karich wrote:
    >> 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 : Fri Mar 30 2007 - 09:21:02 EDT