On Mon, Feb 12, 2001 at 04:33:46PM -0500, Gianni Johansson wrote:
> On Monday 12 February 2001 14:15, Scott wrote:
> 
> > > On Mon, Feb 12, 2001 at 01:29:15PM -0500, Gianni Johansson wrote:
> > > Also, it looks like ThreadPool.runningThreads() should just be:
> > >
> > >     private int runningThreads() {
> > >   return poolGroup.activeCount();
> > >     }
> >
> > No, because pooled threads are technically active, but arent hosting any
> > actual job.
> The problem is that you preallocate the Ethreads.  They don't have 
> java.lang.Threads associated with them until they run their first job.
> i.e. until EThread.begin() is called.  This is what is messing up your 
> counting.  
At any rate thats fixed.

> 
> I don't get what you mean by "technically active".  What matters, besides the
> number of real java.lang.Thread objects???
Do you understand what thread pooling is?  It means that there can be a
few Thread objects technically running, but they are actually just being
held on to waiting for a new job to run.  At that point, we give it a
Runnable and the EThread continues, running the new job.  

 > 
> Also, using activeCount at all seems suspect. because it is approximate:
> http://www.javasoft.com/products/jdk/1.2/docs/api/java/lang/ThreadGroup.html#activeCount()
> 
> Why not just use a counter that's incremented when jobs are dequeued and
> run in ThreadPool.run() and decremented in ThreadPool.reclaim() ?
Because a Thread may die unexpectedly and kill our count.  Its better to
have a moderately inaccurate count than one that can become wildly
inaccurate.

> > had to be a bit more extensive, since it affected the interface as well.
> >
> > Scott
> 
> I applied the patch and retested.  This is still not right.
> 
> Uncomment the printlns in ThreadPool.run and ThreadPool.blockingRun
> and test.
> 
> You will see negative values for runningThreads() in the output.
> 
> Also it looks like EThread.run() never exits.  How do you shutdown cleanly?

There are some serious sync issues between experimental and stable.  The
EThread in stable has the correct behavior:

       for (;;) {
            while (code == null) {
                synchronized(this) {
                    try {
                        wait();
                    } catch (InterruptedException ie) {}
                }
            }

            if (code instanceof ERunnable)
                ((ERunnable)code).setExecutionInstance(this);
            try {
                code.run();
            } catch (Throwable t) {
            } finally {
                code=null;
                if (!host.reclaim(this))
                    return;
            }
        }

-------------- 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/0ca1dc39/attachment.pgp>

Reply via email to