diff options
author | Matthew Newhook <matthew@zeroc.com> | 2014-08-07 14:36:07 -0230 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2014-08-07 14:36:07 -0230 |
commit | b36ae21c88735cbd2c39c5ccde2572a8fcc4e928 (patch) | |
tree | dfd5eee6e7d61a9c6efcbaabe916639009aaa9af /java/src/IceInternal/ThreadPoolWorkQueue.java | |
parent | Add @Override where possible, and remove trailing white space. (diff) | |
download | ice-b36ae21c88735cbd2c39c5ccde2572a8fcc4e928.tar.bz2 ice-b36ae21c88735cbd2c39c5ccde2572a8fcc4e928.tar.xz ice-b36ae21c88735cbd2c39c5ccde2572a8fcc4e928.zip |
ICE-1593 Handling thread interrupts in Java
- Added Ice.BackgroundIO property to perform all IO in a non-user
thread. This makes Ice for Java interrupt safe. This is implemented
by the QueueRequestHanbler.
- EndpointHostResolver now uses an executor instead of a thread.
- Added java/demo/Ice/interrupt and java/test/Ice/interrupt.
- Made several changes that must be ported to C++ & C#.
- InvocationTimeout exceptions can hang forever.
- Connection establishment is always asynchronous.
- RequestHandler.requestTimeout and asyncRequestTimeout have been
renamed to requestCancel and asyncRequestCancel.
Diffstat (limited to 'java/src/IceInternal/ThreadPoolWorkQueue.java')
-rw-r--r-- | java/src/IceInternal/ThreadPoolWorkQueue.java | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/java/src/IceInternal/ThreadPoolWorkQueue.java b/java/src/IceInternal/ThreadPoolWorkQueue.java index 3cf5bc4430e..c46fe75fd3a 100644 --- a/java/src/IceInternal/ThreadPoolWorkQueue.java +++ b/java/src/IceInternal/ThreadPoolWorkQueue.java @@ -9,12 +9,14 @@ package IceInternal; +import java.util.concurrent.ExecutorService; + final class ThreadPoolWorkQueue extends EventHandler { - ThreadPoolWorkQueue(ThreadPool threadPool, Instance instance, Selector selector) + ThreadPoolWorkQueue(Instance instance, ThreadPool threadPool, Selector selector) { + _executor = instance.getQueueExecutor(); _threadPool = threadPool; - _instance = instance; _selector = selector; _destroyed = false; @@ -89,6 +91,7 @@ final class ThreadPoolWorkQueue extends EventHandler { throw new Ice.CommunicatorDestroyedException(); } + assert(item != null); _workItems.add(item); postMessage(); } @@ -115,6 +118,7 @@ final class ThreadPoolWorkQueue extends EventHandler if(!_workItems.isEmpty()) { workItem = _workItems.removeFirst(); + assert(workItem != null); } else { @@ -158,6 +162,25 @@ final class ThreadPoolWorkQueue extends EventHandler public void postMessage() { + if(_executor != null) + { + _executor.submit(new Runnable() { + + @Override + public void run() + { + postMessageInternal(); + } + }); + } + else { + postMessageInternal(); + } + } + + private void + postMessageInternal() + { java.nio.ByteBuffer buf = java.nio.ByteBuffer.allocate(1); buf.put(0, (byte)0); while(buf.hasRemaining()) @@ -166,6 +189,13 @@ final class ThreadPoolWorkQueue extends EventHandler { _fdIntrWrite.write(buf); } + // + // This is thrown if the thread is interrupted. + // + catch(java.nio.channels.ClosedChannelException ex) + { + break; + } catch(java.io.IOException ex) { throw new Ice.SocketException(ex); @@ -174,7 +204,6 @@ final class ThreadPoolWorkQueue extends EventHandler } private final ThreadPool _threadPool; - private final Instance _instance; private final Selector _selector; boolean _destroyed; @@ -182,4 +211,5 @@ final class ThreadPoolWorkQueue extends EventHandler private java.nio.channels.WritableByteChannel _fdIntrWrite; private java.util.LinkedList<ThreadPoolWorkItem> _workItems = new java.util.LinkedList<ThreadPoolWorkItem>(); + private ExecutorService _executor; } |