diff options
author | Mark Spruiell <mes@zeroc.com> | 2005-06-22 22:38:01 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2005-06-22 22:38:01 +0000 |
commit | cf1467033cca90042888c5db6c4ab5296766b500 (patch) | |
tree | 37c3add1a731c3ed60066d1262ae786f75e5c98f /java/src/IceInternal/ThreadPool.java | |
parent | Added support for Ice::FileException. (diff) | |
download | ice-cf1467033cca90042888c5db6c4ab5296766b500.tar.bz2 ice-cf1467033cca90042888c5db6c4ab5296766b500.tar.xz ice-cf1467033cca90042888c5db6c4ab5296766b500.zip |
dynamic thread pool fixes
Diffstat (limited to 'java/src/IceInternal/ThreadPool.java')
-rw-r--r-- | java/src/IceInternal/ThreadPool.java | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/java/src/IceInternal/ThreadPool.java b/java/src/IceInternal/ThreadPool.java index 3da1c6d2084..bfeed4e0ef7 100644 --- a/java/src/IceInternal/ThreadPool.java +++ b/java/src/IceInternal/ThreadPool.java @@ -764,15 +764,42 @@ public final class ThreadPool // Now we check if this thread can be destroyed, based // on a load factor. // - final double loadFactor = 0.05; // TODO: Configurable? - final double oneMinusLoadFactor = 1 - loadFactor; - _load = _load * oneMinusLoadFactor + _inUse * loadFactor; - + + // + // The load factor jumps immediately to the number of + // threads that are currently in use, but decays + // exponentially if the number of threads in use is + // smaller than the load factor. This reflects that we + // create threads immediately when they are needed, + // but want the number of threads to slowly decline to + // the configured minimum. + // + double inUse = (double)_inUse; + if(_load < inUse) + { + _load = inUse; + } + else + { + final double loadFactor = 0.05; // TODO: Configurable? + final double oneMinusLoadFactor = 1 - loadFactor; + _load = _load * oneMinusLoadFactor + _inUse * loadFactor; + } + if(_running > _size) { - int load = (int)(_load + 1); - if(load < _running) + int load = (int)(_load + 0.5); + + //System.out.println("" + _inUse + " " + _running + " " + load + " " + _load); + + // + // We add one to the load factor because one + // additional thread is needed for select(). + // + if(load + 1 < _running) { + //System.out.println("delete thread!!!"); + assert(_inUse > 0); --_inUse; |