On Monday 12 February 2001 17:12, you wrote:

> > > Why not just use a counter that's incremented when jobs are dequeued and
> > run in ThreadPool.run() and decremented in ThreadPool.reclaim() ?
>
> I take it back.  Since reclaim is in the finally block of EThread, this
> will work.  I've worked in the necessary changes.
>
> Bad, could you backport them out of experimental.
>
> GJ:  Try it this time.  It doesnt seem to report negative values.

I retested.  There's still at least one bad bug.

It causes the ThreadPool.run() to intermently stop running jobs even though
less than maxThreads threads are running.

See comments in source:

 /**
     * Activates this ThreadPool. This ThreadPool will grab a queued job,
     * associate it with an EThread, and tell the EThread to begin. It does
     * this over and over again, until it is {@link halt halt}ed.
     */

    public void run() {
        while (run) {
            try {

                // Block until both an EThread is available and a job is
                // queued.


                EThread host=null;
                if (maxThreads > 0 || !threads.isEmpty()) 
                    //                     ^--- LOOK HERE
                            // This condition can evautate to true even when
                            //  threads.size() == 0 and 
                            //  runningThreads() < maxThreads.
                            // In this case pop blocks an EThread is push()'d
                            // into threads.  That could take a long time....

                            host=(EThread)threads.pop();
                else
                    host=new EThread(this);

                Runnable job=(Runnable)jobs.dequeue();
                host.setCode(job);
                host.begin();

                synchronized(this) {
                    runningCount++;
                }

                // Sends a signal to anyone waiting in flush that
                // a job has started to run.

                synchronized(jobs) {
                    jobs.notifyAll();
                }
            } catch (InterruptedException ie) {}
        }
    } 

    Also, the current implementation of reclaim will release all of
    the preallocated Ethreads until only maxPoolThreads remain when the
    ThreadPool quiesces, so why not just preallocate maxPoolThreads in
     the first place, instead of maxThreads?

    //(Re)fills the thread-queue with maxThreads EThreads
    private void fillThreadstack() {
        while (threads.size()<maxThreads) {
            threads.push(new EThread(this));
        }
    }


   -- gj
-- 
Web page inside Freenet:
freenet:MSK at SSK@enI8YFo3gj8UVh-Au0HpKMftf6QQAgE/homepage//

_______________________________________________
Devl mailing list
Devl at freenetproject.org
http://www.uprizer.com/mailman/listinfo/devl

Reply via email to