diff options
Diffstat (limited to 'java/src/IceInternal/ThreadPool.java')
-rw-r--r-- | java/src/IceInternal/ThreadPool.java | 142 |
1 files changed, 70 insertions, 72 deletions
diff --git a/java/src/IceInternal/ThreadPool.java b/java/src/IceInternal/ThreadPool.java index ea80b046a77..4a84278ab6c 100644 --- a/java/src/IceInternal/ThreadPool.java +++ b/java/src/IceInternal/ThreadPool.java @@ -524,7 +524,6 @@ public final class ThreadPool } catch(Ice.DatagramLimitException ex) // Expected. { - handler._stream.pos(0); handler._stream.resize(0, true); continue; } @@ -550,7 +549,6 @@ public final class ThreadPool _instance.initializationData().logger.warning( "datagram connection exception:\n" + ex + "\n" + handler.toString()); } - handler._stream.pos(0); handler._stream.resize(0, true); } else @@ -618,83 +616,93 @@ 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) { - assert(_inUse > 0); - --_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); + + // + // 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; } + // + // Do not wait to be promoted again to release these objects. + // + handler = null; + workItem = null; + while(!_promote) { try @@ -793,8 +801,8 @@ public final class ThreadPool throw e; } - byte messageType = stream.readByte(); - byte compress = stream.readByte(); + stream.readByte(); // messageType + stream.readByte(); // compress int size = stream.readInt(); if(size < Protocol.headerSize) { @@ -962,23 +970,13 @@ public final class ThreadPool { promote = ThreadPool.this.run(stream); } - catch(Ice.LocalException ex) - { - java.io.StringWriter sw = new java.io.StringWriter(); - java.io.PrintWriter pw = new java.io.PrintWriter(sw); - ex.printStackTrace(pw); - pw.flush(); - String s = "exception in `" + _prefix + "' thread " + getName() + ":\n" + sw.toString(); - _instance.initializationData().logger.error(s); - promote = true; - } catch(java.lang.Exception ex) { java.io.StringWriter sw = new java.io.StringWriter(); java.io.PrintWriter pw = new java.io.PrintWriter(sw); ex.printStackTrace(pw); pw.flush(); - String s = "unknown exception in `" + _prefix + "' thread " + getName() + ":\n" + sw.toString(); + String s = "exception in `" + _prefix + "' thread " + getName() + ":\n" + sw.toString(); _instance.initializationData().logger.error(s); promote = true; } |