avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leo Sutic" <leo.su...@inspireinfrastructure.com>
Subject RE: Performance questions about ECM
Date Sat, 09 Mar 2002 14:41:39 GMT


> From: Vincent Massol [mailto:vmassol@octo.com]
>
> I agree with all you have said. However, my biggest fear (and you have
> not yet convinced me !) is that even though synchronization is fast it
> will still block *all* threads during that time.

So you mean that:

class WorkerThread extends Thread {
    int number;
    Hack hack;
    
    public WorkerThread (int number, Hack hack) {
        this.number = number;
        this.hack = hack;
    }
    
    public void run () {
        switch (number) {
        case 0:
        case 1:
            hack.syncMethod();
            break;
        case 2:
            hack.method();
            break;
        }
    }
}

public class Hack {
    
    public synchronized void syncMethod () {
        System.out.println ("entering sync method");
        try {
            Thread.sleep (1000);
        } catch (Throwable t) {
        }
        System.out.println ("leaving sync method");
    }
    
    public void method () {
        for (int i = 0; i < 10; i++) {
            System.out.println ("in method");
            try {
                Thread.sleep (200);
            } catch (Throwable t) {
            }
        }
    }
    
    public static void main (String args[]) throws Exception {
        new Hack().run();
    }
    
    public void run () throws Exception {
        WorkerThread thread[] = new WorkerThread[3];
         thread[0] = new WorkerThread (0, this);
         thread[1] = new WorkerThread (1, this);
         thread[2] = new WorkerThread (2, this);
        
        for (int i = 0; i < 3; i++) {
            thread[i].start();
        }
        
        for (int i = 0; i < 3; i++) {
            thread[i].join();
        }
    }
}

The third worker thread will stop while the second or first
compete for the monitor of syncMethod()? (Answer: no.) I'm not
quite sure that I follow you here...

A thread will only block if it is actually waiting for a 
monitor.

> Object creation may
> take a bit longer but they won't block any other thread. So I'm more
> worried about synchronization.

And you are sure that there aren't any locks associated with the 
common java heap or the object nurseries?

To answer your question: No. I know of no such CM implementation, and
if you need one I suspect you will have to roll your own.

I also think that you are wasting your time doing so, as your SQL
queries probably have X synchronizations associated with them, and
as the VM itself probably has a set of locks inside it that you have
no control over. Not to mention the locks in the OS and networking 
code.

Do not take the above paragraph as criticism of your skill. Your system
works - that's undeniable and proof enough that you know what you are 
doing. But I do not see how synchronization could
cause you significant slowdown compared to the cascading object
creation your single-threaded components produce. Remember, that
cascade goes through the ECM's synchronization as well. If you
removed the sync, all you would remove is the time it takes to aquire
a monitor. If you removed the cascade of object creation, you'd lose
that, as well as object creation times.

/LS

--
To unsubscribe, e-mail:   <mailto:avalon-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-dev-help@jakarta.apache.org>


Mime
View raw message