On Mon, Feb 12, 2001 at 12:33:25PM -0500, Gianni Johansson wrote:
> On Monday 12 February 2001 09:32, Scott wrote:
> 
> > Yeah, that seems right.  There should be a ThreadGroup containing the
> > threads, and runningThreads should be the number of active threads in that
> > group minus those in the thread pool.
> >
> > Attached is a patch.  I've updated the experimental tree if someone can
> > patch this against the stable tree.
> >
> >     Scott
> 
> Hi Scott:
> This doesn't look quite right.  How do the java.lang.Thread objects managed 
> by the ThreadPool ever get into the poolGroup ThreadGroup?
> 
Ack.

> It looks like tg was omitted from the superclass constructor arguments 
> in ThreadPool.ThreadPool.
> 
> See comments in code snippet below.
> 
> -- gj
> 
>   /**
>      * Creates a ThreadPool with a fixed number of concurrently
>      * executable jobs.  This also allocates a job queue, so that
>      * new jobs can be inserted in a non-blocking manner even if all
>      * maxThreads threads are occupied. This ThreadPool allows up to a 
>      * total of maxJobs running and queued jobs.
>      *
>      * @param tg      The ThreadGroup to use for the pool and all it's 
>      * children.
>      * @param maxThreads The number of jobs that can be active at any
>      * one time.
>      * @param maxJobs The maximum total number of allowable jobs.  {@link
>      * run run()} returns false to turn away additional jobs past this point.
>      */
>     public ThreadPool(ThreadGroup tg, int maxPool, int maxThreads, 
>                     int maxJobs) {
>       super("ThreadPool");
>             // ^--- LOOK HERE.
>             // Shouldn't this  be:
>             // super(tg, "ThreadPool");
>             //
No, I decided *not* to make the ThreadPool thread part of the group of
managed threads.

But yeah, your right about the group thing.  Here's the new patch, which
had to be a bit more extensive, since it affected the interface as well.

Scott

-------------- next part --------------
Common subdirectories: Freenet-old/thread/CVS and Freenet/thread/CVS
diff -ud Freenet-old/thread/EThread.java Freenet/thread/EThread.java
--- Freenet-old/thread/EThread.java     Tue Jan 16 00:34:19 2001
+++ Freenet/thread/EThread.java Mon Feb 12 14:10:31 2001
@@ -56,7 +56,7 @@
      */
     protected void begin() {
        if (executor==null){
-           executor=new Thread(this);
+           executor=host.getThread(this);
            executor.start();
        }
        synchronized (this) {
@@ -102,8 +102,7 @@
            } catch (Throwable t) {
            } finally {
                code=null;
-               if (!host.reclaim(this))
-                   return;
+               host.reclaim(this);
            }
        }
     }
diff -ud Freenet-old/thread/ThreadManager.java Freenet/thread/ThreadManager.java
--- Freenet-old/thread/ThreadManager.java       Tue Jan 16 00:34:19 2001
+++ Freenet/thread/ThreadManager.java   Mon Feb 12 14:10:00 2001
@@ -45,7 +45,7 @@
      *
      * @param e The E-Thread to return.
      */
-    public boolean reclaim(EThread e);
+    public void reclaim(EThread e);

     /**
      * Begins operation of this thread-manager.  Should be called
@@ -69,6 +69,8 @@
      * be run).
      */
     public void flush();
+
+    Thread getThread(Runnable r);
 }


diff -ud Freenet-old/thread/ThreadPool.java Freenet/thread/ThreadPool.java
--- Freenet-old/thread/ThreadPool.java  Mon Feb 12 14:13:43 2001
+++ Freenet/thread/ThreadPool.java      Mon Feb 12 14:10:12 2001
@@ -53,7 +53,8 @@
      * Creates a ThreadPool with a fixed number of concurrently
      * executable jobs.  This also allocates a job queue, so that
      * an unlimited number of new jobs can be inserted in a non-blocking
-     * manner even if all maxThreads threads are occupied.
+     * manner even if all
+     * maxThreads threads are occupied.
      *
      * @param tg      The ThreadGroup to use for the pool and all it's 
      * children.
@@ -69,8 +70,8 @@
      * Creates a ThreadPool with a fixed number of concurrently
      * executable jobs.  This also allocates a job queue, so that
      * new jobs can be inserted in a non-blocking manner even if all
-     * maxThreads threads are occupied. This ThreadPool allows up to a 
-     * total of maxJobs running and queued jobs.
+     * maxThreads threads are occupied. This ThreadPool allows up to a total 
of maxJobs
+     * running and queued jobs.
      *
      * @param maxThreads The number of jobs that can be active at any
      * one time.
@@ -86,8 +87,8 @@
      * Creates a ThreadPool with a fixed number of concurrently
      * executable jobs.  This also allocates a job queue, so that
      * new jobs can be inserted in a non-blocking manner even if all
-     * maxThreads threads are occupied. This ThreadPool allows up to a 
-     * total of maxJobs running and queued jobs.
+     * maxThreads threads are occupied. This ThreadPool allows up to a total 
of maxJobs
+     * running and queued jobs.
      *
      * @param tg      The ThreadGroup to use for the pool and all it's 
      * children.
@@ -122,17 +123,12 @@
      *
      * @param e The EThread to reclaim.
      */
-    public boolean reclaim(EThread e) {
-       boolean rv=false;
-       if (maxThreads == 0 || threads.size()<maxPoolThreads) {
-           threads.push(e);
-           rv=true;
-       } 
-
+    public void reclaim(EThread e) {
+       if (maxThreads > 0 || threads.size()<maxPoolThreads)
+       threads.push(e);
        synchronized(threads) {
            threads.notifyAll();
        }
-       return rv;
     }

     private int runningThreads() {
@@ -193,6 +189,13 @@
     public void halt() {
        run=false;
         interrupt();
+    }
+
+    /**
+     * Returns a Thread to host an EThread
+     */
+    public Thread getThread(Runnable r) {
+       return new Thread(poolGroup, r);
     }

     /**
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
URL: 
<https://emu.freenetproject.org/pipermail/devl/attachments/20010212/b3e4ea2c/attachment.pgp>

Reply via email to