diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/src/IceInternal/RetryQueue.java | 40 | ||||
-rw-r--r-- | java/src/IceInternal/RetryTask.java | 23 |
2 files changed, 51 insertions, 12 deletions
diff --git a/java/src/IceInternal/RetryQueue.java b/java/src/IceInternal/RetryQueue.java index 4d6f8144410..311d53b4cc3 100644 --- a/java/src/IceInternal/RetryQueue.java +++ b/java/src/IceInternal/RetryQueue.java @@ -31,20 +31,50 @@ public class RetryQueue synchronized public void destroy() { + java.util.HashSet<RetryTask> keep = new java.util.HashSet<RetryTask>(); for(RetryTask task : _requests) { - task.destroy(); + if(!task.destroy()) + { + keep.add(task); + } } - _requests.clear(); + _requests = keep; _instance = null; + + // + // Wait for the tasks to be executed, it shouldn't take long + // since they couldn't be canceled. If interrupted, we + // preserve the interrupt. + // + boolean interrupted = false; + while(!_requests.isEmpty()) + { + try + { + wait(); + } + catch(InterruptedException ex) + { + interrupted = true; + } + } + if(interrupted) + { + Thread.currentThread().interrupt(); + } } - synchronized boolean + synchronized void remove(RetryTask task) { - return _requests.remove(task); + _requests.remove(task); + if(_instance == null && _requests.isEmpty()) + { + notify(); + } } private Instance _instance; - final private java.util.HashSet<RetryTask> _requests = new java.util.HashSet<RetryTask>(); + private java.util.HashSet<RetryTask> _requests = new java.util.HashSet<RetryTask>(); } diff --git a/java/src/IceInternal/RetryTask.java b/java/src/IceInternal/RetryTask.java index 2c991f65819..713c8bc856a 100644 --- a/java/src/IceInternal/RetryTask.java +++ b/java/src/IceInternal/RetryTask.java @@ -21,17 +21,26 @@ class RetryTask implements Runnable public void run() { - if(_queue.remove(this)) - { - _outAsync.processRetry(false); - } + _outAsync.processRetry(false); + + // + // NOTE: this must be called last, destroy() blocks until all task + // are removed to prevent the client thread pool to be destroyed + // (we still need the client thread pool at this point to call + // exception callbacks with CommunicatorDestroyedException). + // + _queue.remove(this); } - public void + public boolean destroy() { - _future.cancel(false); - _outAsync.processRetry(true); + if(_future.cancel(false)) + { + _outAsync.processRetry(true); + return true; + } + return false; } public void setFuture(java.util.concurrent.Future<?> future) |