summaryrefslogtreecommitdiff
path: root/java/src/IceInternal/ThreadPool.java
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2009-02-10 15:08:16 +0100
committerBenoit Foucher <benoit@zeroc.com>2009-02-11 12:03:17 +0100
commit0a3e143c041ef47dc13bc84d742bc472923f6557 (patch)
treecae8cdf83a82094d848ad31ffceee16ca7634f73 /java/src/IceInternal/ThreadPool.java
parentFixed bug 3706 - invalid SocketException handler (diff)
downloadice-0a3e143c041ef47dc13bc84d742bc472923f6557.tar.bz2
ice-0a3e143c041ef47dc13bc84d742bc472923f6557.tar.xz
ice-0a3e143c041ef47dc13bc84d742bc472923f6557.zip
Fixed bug 3720 - Added check for dynamic thread pool
Diffstat (limited to 'java/src/IceInternal/ThreadPool.java')
-rw-r--r--java/src/IceInternal/ThreadPool.java118
1 files changed, 61 insertions, 57 deletions
diff --git a/java/src/IceInternal/ThreadPool.java b/java/src/IceInternal/ThreadPool.java
index f75ebdfecc1..d6d1235a821 100644
--- a/java/src/IceInternal/ThreadPool.java
+++ b/java/src/IceInternal/ThreadPool.java
@@ -616,79 +616,83 @@ public final class ThreadPool
handler._serializing = false;
}
- //
- // First we reap threads that have been
- // destroyed before.
- //
- int sz = _threads.size();
- assert(_running <= sz);
- if(_running < sz)
+
+ if(_size < _sizeMax) // Dynamic thread pool
{
- java.util.Iterator<EventHandlerThread> i = _threads.iterator();
- while(i.hasNext())
+ //
+ // First we reap threads that have been
+ // destroyed before.
+ //
+ int sz = _threads.size();
+ assert(_running <= sz);
+ if(_running < sz)
{
- EventHandlerThread thread = i.next();
-
- if(!thread.isAlive())
+ java.util.Iterator<EventHandlerThread> i = _threads.iterator();
+ while(i.hasNext())
{
- try
- {
- thread.join();
- i.remove();
- }
- catch(InterruptedException ex)
+ EventHandlerThread thread = i.next();
+
+ if(!thread.isAlive())
{
+ try
+ {
+ thread.join();
+ i.remove();
+ }
+ catch(InterruptedException ex)
+ {
+ }
}
}
}
- }
- //
- // Now we check if this thread can be destroyed, based
- // on a load factor.
- //
-
- //
- // 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 + 0.5);
+ //
+ // Now we check if this thread can be destroyed, based
+ // on a load factor.
+ //
//
- // We add one to the load factor because one
- // additional thread is needed for select().
+ // 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.
//
- if(load + 1 < _running)
+ double inUse = (double)_inUse;
+ if(_load < inUse)
+ {
+ _load = inUse;
+ }
+ else
{
- assert(_inUse > 0);
- --_inUse;
+ final double loadFactor = 0.05; // TODO: Configurable?
+ final double oneMinusLoadFactor = 1 - loadFactor;
+ _load = _load * oneMinusLoadFactor + _inUse * loadFactor;
+ }
+
+ if(_running > _size)
+ {
+ int load = (int)(_load + 0.5);
+
+ //
+ // We add one to the load factor because one
+ // additional thread is needed for select().
+ //
+ if(load + 1 < _running)
+ {
+ assert(_inUse > 0);
+ --_inUse;
- assert(_running > 0);
- --_running;
+ assert(_running > 0);
+ --_running;
- return false;
+ return false;
+ }
}
}
-
+
assert(_inUse > 0);
--_inUse;
}