diff options
Diffstat (limited to 'java/src/IceInternal/ThreadPool.java')
-rw-r--r-- | java/src/IceInternal/ThreadPool.java | 118 |
1 files changed, 57 insertions, 61 deletions
diff --git a/java/src/IceInternal/ThreadPool.java b/java/src/IceInternal/ThreadPool.java index e3eecdd817a..5c70893d61f 100644 --- a/java/src/IceInternal/ThreadPool.java +++ b/java/src/IceInternal/ThreadPool.java @@ -316,7 +316,6 @@ public final class ThreadPool { if(current._handler != null) { - thread.setState(Ice.Instrumentation.ThreadState.ThreadStateInUseForIO); try { current._handler.message(current); @@ -334,7 +333,6 @@ public final class ThreadPool } else if(select) { - thread.setState(Ice.Instrumentation.ThreadState.ThreadStateIdle); try { _selector.select(_serverIdleTime); @@ -412,6 +410,7 @@ public final class ThreadPool current._ioCompleted = false; current._handler = _nextHandler.next(); current.operation = current._handler._ready; + thread.setState(Ice.Instrumentation.ThreadState.ThreadStateInUseForIO); } else { @@ -434,6 +433,7 @@ public final class ThreadPool { _selector.startSelect(); select = true; + thread.setState(Ice.Instrumentation.ThreadState.ThreadStateIdle); } } else if(_sizeMax > 1) @@ -452,7 +452,7 @@ public final class ThreadPool } } - void + synchronized void ioCompleted(ThreadPoolCurrent current) { current._ioCompleted = true; // Set the IO completed flag to specify that ioCompleted() has been called. @@ -461,81 +461,75 @@ public final class ThreadPool if(_sizeMax > 1) { - synchronized(this) + --_inUseIO; + + if((current.operation & SocketOperation.Read) != 0 && current._handler.hasMoreData()) { - --_inUseIO; + _selector.hasMoreData(current._handler); + } + + if(_serialize && !_destroyed) + { + _selector.disable(current._handler, current.operation); + } - if((current.operation & SocketOperation.Read) != 0 && current._handler.hasMoreData()) - { - _selector.hasMoreData(current._handler); - } + if(current._leader) + { + // + // If this thread is still the leader, it's time to promote a new leader. + // + promoteFollower(current); + } + else if(_promote && (_nextHandler.hasNext() || _inUseIO == 0)) + { + notify(); + } - if(_serialize && !_destroyed) - { - _selector.disable(current._handler, current.operation); - } + assert(_inUse >= 0); + ++_inUse; - if(current._leader) - { - // - // If this thread is still the leader, it's time to promote a new leader. - // - promoteFollower(current); - } - else if(_promote && (_nextHandler.hasNext() || _inUseIO == 0)) - { - notify(); - } - - assert(_inUse >= 0); - ++_inUse; + if(_inUse == _sizeWarn) + { + String s = "thread pool `" + _prefix + "' is running low on threads\n" + + "Size=" + _size + ", " + "SizeMax=" + _sizeMax + ", " + "SizeWarn=" + _sizeWarn; + _instance.initializationData().logger.warning(s); + } - if(_inUse == _sizeWarn) + if(!_destroyed) + { + assert(_inUse <= _threads.size()); + if(_inUse < _sizeMax && _inUse == _threads.size()) { - String s = "thread pool `" + _prefix + "' is running low on threads\n" - + "Size=" + _size + ", " + "SizeMax=" + _sizeMax + ", " + "SizeWarn=" + _sizeWarn; - _instance.initializationData().logger.warning(s); - } - - if(!_destroyed) - { - assert(_inUse <= _threads.size()); - if(_inUse < _sizeMax && _inUse == _threads.size()) + if(_instance.traceLevels().threadPool >= 1) { - if(_instance.traceLevels().threadPool >= 1) - { - String s = "growing " + _prefix + ": Size=" + (_threads.size() + 1); - _instance.initializationData().logger.trace(_instance.traceLevels().threadPoolCat, s); - } + String s = "growing " + _prefix + ": Size=" + (_threads.size() + 1); + _instance.initializationData().logger.trace(_instance.traceLevels().threadPoolCat, s); + } - try + try + { + EventHandlerThread thread = new EventHandlerThread(_threadPrefix + "-" + _threadIndex++); + _threads.add(thread); + if(_hasPriority) { - EventHandlerThread thread = new EventHandlerThread(_threadPrefix + "-" + _threadIndex++); - _threads.add(thread); - if(_hasPriority) - { - thread.start(_priority); - } - else - { - thread.start(java.lang.Thread.NORM_PRIORITY); - } + thread.start(_priority); } - catch(RuntimeException ex) + else { - String s = "cannot create thread for `" + _prefix + "':\n" + Ex.toString(ex); - _instance.initializationData().logger.error(s); + thread.start(java.lang.Thread.NORM_PRIORITY); } } + catch(RuntimeException ex) + { + String s = "cannot create thread for `" + _prefix + "':\n" + Ex.toString(ex); + _instance.initializationData().logger.error(s); + } } } } else if((current.operation & SocketOperation.Read) != 0 && current._handler.hasMoreData()) { - synchronized(this) - { - _selector.hasMoreData(current._handler); - } + _selector.hasMoreData(current._handler); } } @@ -627,6 +621,7 @@ public final class ThreadPool public void updateObserver() { + // Must be called with the thread pool mutex locked Ice.Instrumentation.CommunicatorObserver obsv = _instance.initializationData().observer; if(obsv != null) { @@ -638,9 +633,10 @@ public final class ThreadPool } } - void + public void setState(Ice.Instrumentation.ThreadState s) { + // Must be called with the thread pool mutex locked if(_observer != null) { if(_state != s) |