[Jukebox-cvs] CVS update: J4/src/java/gnu/j4/service DefaultThreadFactory.java PooledThreadFactory.j
Brought to you by:
vtt
From: CVS B. <vt...@fr...> - 2000-08-28 18:26:14
|
User: vt Date: 00/08/28 11:26:19 Modified: src/java/gnu/j4/service ActiveService.java Makefile.am PassiveService.java Added: src/java/gnu/j4/service DefaultThreadFactory.java PooledThreadFactory.java ThreadFactory.java Log: Introduced the thread pooling. Implementation is incomplete, currently it uses just a mockup of a thread pool. Revision Changes Path 1.6 +8 -5 J4/src/java/gnu/j4/service/ActiveService.java CVSWEB Options: ------------------- CVSWeb: Annotate this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/service/ActiveService.java?annotate=1.6&cvsroot=jukebox4 CVSWeb: View this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/service/ActiveService.java?rev=1.6&content-type=text/x-cvsweb-markup&cvsroot=jukebox4 CVSWeb: Diff to previous version: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/service/ActiveService.java.diff?r1=1.6&r2=1.5&cvsroot=jukebox4 ----------------------------------- Index: ActiveService.java =================================================================== RCS file: /usr/local/cvs/J4/src/java/gnu/j4/service/ActiveService.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ActiveService.java 2000/03/03 04:20:22 1.5 +++ ActiveService.java 2000/08/28 18:26:18 1.6 @@ -6,7 +6,7 @@ * then shuts down (observing some post-conditions at shutdown). * * @author Copyright © <a href="mailto:vt...@fr...">Vadim Tkachenko</a> 1995-2000 - * @version $Id: ActiveService.java,v 1.5 2000/03/03 04:20:22 vt Exp $ + * @version $Id: ActiveService.java,v 1.6 2000/08/28 18:26:18 vt Exp $ * @see PassiveService */ public abstract class ActiveService extends PassiveService { @@ -26,7 +26,10 @@ abstract protected void execute() throws InterruptedException, Throwable; protected void startCore() { - core = new ActiveWrapper(tGroup,this); + + ActiveWrapper aw = new ActiveWrapper(this); + + core = tf.allocate(tGroup, aw, getClass().getName()); core.start(); } @@ -49,12 +52,12 @@ } } - protected class ActiveWrapper extends Thread { + protected class ActiveWrapper implements Runnable { protected ActiveService target; + + protected ActiveWrapper(ActiveService target) { - protected ActiveWrapper(ThreadGroup tGroup,ActiveService target) { - super(tGroup,target.getClass().getName()); this.target = target; } 1.11 +5 -2 J4/src/java/gnu/j4/service/Makefile.am CVSWEB Options: ------------------- CVSWeb: Annotate this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/service/Makefile.am?annotate=1.11&cvsroot=jukebox4 CVSWeb: View this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/service/Makefile.am?rev=1.11&content-type=text/x-cvsweb-markup&cvsroot=jukebox4 CVSWeb: Diff to previous version: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/service/Makefile.am.diff?r1=1.11&r2=1.10&cvsroot=jukebox4 ----------------------------------- Index: Makefile.am =================================================================== RCS file: /usr/local/cvs/J4/src/java/gnu/j4/service/Makefile.am,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- Makefile.am 2000/07/06 10:47:09 1.10 +++ Makefile.am 2000/08/28 18:26:18 1.11 @@ -1,4 +1,4 @@ -# $Id: Makefile.am,v 1.10 2000/07/06 10:47:09 vt Exp $ +# $Id: Makefile.am,v 1.11 2000/08/28 18:26:18 vt Exp $ EXTRA_DIST = package.html SUBDIRS = net @@ -12,7 +12,10 @@ ResourcePool.java \ RunnableService.java \ Service.java \ - ServiceUnavailableException.java + ServiceUnavailableException.java \ + ThreadFactory.java \ + DefaultThreadFactory.java \ + PooledThreadFactory.java JMX_FILES = MBeanServerWrapper.java 1.15 +12 -9 J4/src/java/gnu/j4/service/PassiveService.java CVSWEB Options: ------------------- CVSWeb: Annotate this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/service/PassiveService.java?annotate=1.15&cvsroot=jukebox4 CVSWeb: View this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/service/PassiveService.java?rev=1.15&content-type=text/x-cvsweb-markup&cvsroot=jukebox4 CVSWeb: Diff to previous version: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/service/PassiveService.java.diff?r1=1.15&r2=1.14&cvsroot=jukebox4 ----------------------------------- Index: PassiveService.java =================================================================== RCS file: /usr/local/cvs/J4/src/java/gnu/j4/service/PassiveService.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- PassiveService.java 2000/07/19 21:31:55 1.14 +++ PassiveService.java 2000/08/28 18:26:18 1.15 @@ -49,8 +49,8 @@ * href="http://www.eiffel.com/doc/manuals/technology/contract/ariane/index.html" * target="_top">$500 million mistake</a>. * - * @author Copyright © <a href="mailto:vt...@fr...">Vadim Tkachenko</a> 1995-1998 - * @version $Id: PassiveService.java,v 1.14 2000/07/19 21:31:55 vt Exp $ + * @author Copyright © <a href="mailto:vt...@fr...">Vadim Tkachenko</a> 1995-2000 + * @version $Id: PassiveService.java,v 1.15 2000/08/28 18:26:18 vt Exp $ * @see ActiveService */ public abstract class PassiveService extends LogAware implements RunnableService { @@ -60,6 +60,8 @@ */ public final static String CH_WRAPPER = "service/wrapper"; + protected ThreadFactory tf = new DefaultThreadFactory(); + /** * Execute the startup sequence. * @@ -602,7 +604,9 @@ */ protected void startCore() { - core = new PassiveWrapper(tGroup, new StartupWrapper(this), semUp); + PassiveWrapper pw = new PassiveWrapper(new StartupWrapper(this), semUp); + + core = tf.allocate(tGroup, pw, pw.target.getClass().getName()); core.start(); } @@ -644,7 +648,9 @@ */ protected void stopCore() { - core = new PassiveWrapper(tGroup, new ShutdownWrapper(this), semDown); + PassiveWrapper pw = new PassiveWrapper(new ShutdownWrapper(this), semDown); + + core = tf.allocate(tGroup, pw, pw.target.getClass().getName()); core.start(); } @@ -667,7 +673,7 @@ * * @see PassiveService.MethodWrapper */ - protected class PassiveWrapper extends Thread { + protected class PassiveWrapper implements Runnable { /** * Call target. @@ -682,17 +688,14 @@ /** * Create a new wrapper. * - * @param tGroup ThreadGroup to belong to - * * @param target Method wrapper providing the invocation target and the proper method. * * @param sem Event semaphore to trigger with the result of the method call. * * @see PassiveService#tGroup */ - PassiveWrapper(ThreadGroup tGroup, MethodWrapper target, EventSemaphore sem) { + PassiveWrapper(MethodWrapper target, EventSemaphore sem) { - super(tGroup, target.target.getClass().getName()); this.target = target; this.sem = sem; } 1.1 J4/src/java/gnu/j4/service/DefaultThreadFactory.java CVSWEB Options: ------------------- CVSWeb: Annotate this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/service/DefaultThreadFactory.java?annotate=1.1&cvsroot=jukebox4 CVSWeb: View this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/service/DefaultThreadFactory.java?rev=1.1&content-type=text/x-cvsweb-markup&cvsroot=jukebox4 ----------------------------------- Index: DefaultThreadFactory.java =================================================================== package gnu.j4.service; /** * Default thread factory. * * Just creates a new thread object every time a thread is requested. This * is done to ensure that the thread creation logic is fine. No performance * improvements are achieved, on the contrary, it introduces a method call * overhead on every thread creation request. * * @author Copyright © <a href="mailto:vt...@fr...">Vadim Tkachenko</a> 1995-2000 * @version $Id: DefaultThreadFactory.java,v 1.1 2000/08/28 18:26:18 vt Exp $ */ public class DefaultThreadFactory extends ThreadFactory { /** * Log facility to use. */ public static final String CH_DTF = "ThreadFactory/default"; /** * Obtain a thread reference. * * The <code>Thread</code> object returned by this method must be in a * state that allows invoking <code>start()</code> method on it. * * @param tg Thread group to belong to. This parameter is required to * avoid the security implications in case the default thread group is * not the one we want. * * @param r The runnable object for the newly allocated thread to run. * * @param name Name for the thread to be returned. * * @return Reference to a thread object. */ public Thread allocate(ThreadGroup tg, Runnable r, String name) { complain(LOG_DEBUG, CH_DTF, "Allocated " + tg.getName() + "/" + name); return new Thread(tg, r, name); } /** * Return a thread reference to the pool. * * @param t Thread object to make available to the pool again. */ public void release(Thread t) { complain(LOG_DEBUG, CH_DTF, "Freed " + t.getThreadGroup().getName() + "/" + t.getName()); } } 1.1 J4/src/java/gnu/j4/service/PooledThreadFactory.java CVSWEB Options: ------------------- CVSWeb: Annotate this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/service/PooledThreadFactory.java?annotate=1.1&cvsroot=jukebox4 CVSWeb: View this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/service/PooledThreadFactory.java?rev=1.1&content-type=text/x-cvsweb-markup&cvsroot=jukebox4 ----------------------------------- Index: PooledThreadFactory.java =================================================================== package gnu.j4.service; /** * Pooled thread factory. * * Instead of just returning a new thread like a {@link DefaultThreadFactory * DefaultThreadFactory} does, this object tries to pool and reuse the * threads. * * @author Copyright © <a href="mailto:vt...@fr...">Vadim Tkachenko</a> 1995-2000 * @version $Id: PooledThreadFactory.java,v 1.1 2000/08/28 18:26:19 vt Exp $ */ public class PooledThreadFactory extends ThreadFactory { /** * Log facility to use. */ public static final String CH_PTF = "ThreadFactory/pooled"; /** * Obtain a thread reference. * * The <code>Thread</code> object returned by this method must be in a * state that allows invoking <code>start()</code> method on it. * * @param tg Thread group to belong to. This parameter is required to * avoid the security implications in case the default thread group is * not the one we want. * * @param r The runnable object for the newly allocated thread to run. * * @param name Name for the thread to be returned. * * @return Reference to a thread object. */ public Thread allocate(ThreadGroup tg, Runnable r, String name) { complain(LOG_DEBUG, CH_PTF, "Allocated " + tg.getName() + "/" + name); throw new Error("Not Implemented"); } /** * Return a thread reference to the pool. * * @param t Thread object to make available to the pool again. */ public void release(Thread t) { complain(LOG_DEBUG, CH_PTF, "Freed " + t.getThreadGroup().getName() + "/" + t.getName()); throw new Error("Not Implemented"); } } 1.1 J4/src/java/gnu/j4/service/ThreadFactory.java CVSWEB Options: ------------------- CVSWeb: Annotate this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/service/ThreadFactory.java?annotate=1.1&cvsroot=jukebox4 CVSWeb: View this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/service/ThreadFactory.java?rev=1.1&content-type=text/x-cvsweb-markup&cvsroot=jukebox4 ----------------------------------- Index: ThreadFactory.java =================================================================== package gnu.j4.service; import gnu.j4.core.LogAware; /** * An abstract thread factory. * * Using a thread factory instead of a <code>Thread</code> constructor * allows to have a fine-grained control over a thread creation and * destruction. Keeping in mind that there are issues with the thread * garbage collection, this may improve the performance quite a bit. * * @author Copyright © <a href="mailto:vt...@fr...">Vadim Tkachenko</a> 1995-2000 * @version $Id: ThreadFactory.java,v 1.1 2000/08/28 18:26:19 vt Exp $ */ abstract public class ThreadFactory extends LogAware { /** * Obtain a thread reference. * * The <code>Thread</code> object returned by this method must be in a * state that allows invoking <code>start()</code> method on it. * * @param tg Thread group to belong to. This parameter is required to * avoid the security implications in case the default thread group is * not the one we want. * * @param r The runnable object for the newly allocated thread to run. * * @param name Name for the thread to be returned. * * @return Reference to a thread object. */ abstract public Thread allocate(ThreadGroup tg, Runnable r, String name); /** * Return a thread reference to the pool. * * @param t Thread object to make available to the pool again. */ abstract public void release(Thread t); } |