On Fri, 4 May 2001, Peter Donald wrote:

> At 12:29  3/5/01 -0700, Earl Hood wrote:
> >On May 3, 2001 at 12:46, "Michael Gerdau" wrote:
> 
> Unfortunately that doesn't cut it as usually you need to have Thread
> implement a particular class so it replaces itself back in pool after it
> has done a run() on it' client. The way I am just about to redesign the
> Avalon thread pool is as follows
> 
> interface ThreadPool
> {
>   void executeAndWait( Runnable work ) throws ThreadException;
>   void executeAndWait( Executable work ) throws ThreadException;
> 
>   ThreadControl execute( Runnable work );
>   ThreadControl execute( Executable work );
> }

I was thinking of something simpler:

interface SimpleThreadPool {
   void run( Runnable r );
}

That's all you need in most cases.

On top of this you can add other (optional) APIs ( like ThreadPoolRunnable
in tomcat, that saves a hashtable lookup, or any other fancy methods
). And of course, the implementation migh have some setters and getters to
configure the pool and get info - but that's specific to each
implementation.


IMHO a big problem with java is that it's far too easy to create
interfaces.



Costin

> 
> class ThreadException
> {
> ...
>   Throwable getRootCause() { ... }
> ...
> }
> 
> interface ThreadControl
> {
>   void interupt() throws Exception;
>   boolean isValid();
>   boolean isFinished();
>   Throwable getThrowable();
> }
> 
> //Method gets called for thread hook right before you dispatch work
> interface ThreadHook
> {
>   void setupThread() {}
> }
> 
> executeAndWait is useful when you are using the pool to cross
> thread/protection boundaries (Very very useful in writing software like
> tomcat/james/Avalon-phoenix). 
> 
> execute returns a control so you can control all the important features of
> thread directly.
> 
> ThreadHook.setupThread() is called right before a set of work is dispatched
> and usually used to set name of thread, contextClassLoader and any other
> thread local variables.
> 
> All other thread features (ie priority, whether thread is a daemon thread,
> etc) are determined by pool.
> 
> I haven't found any places where the above design won't work - what do you
> think about it?
> 
> Cheers,
> 
> Pete
> 
> *-----------------------------------------------------*
> | "Faced with the choice between changing one's mind, |
> | and proving that there is no need to do so - almost |
> | everyone gets busy on the proof."                   |
> |              - John Kenneth Galbraith               |
> *-----------------------------------------------------*
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to