Archived

This forum has been archived. Please start a new discussion on GitHub.

Thread interrupted

I want to interrupt running thread while something slow responding.
This post described exactly the problem:
http://www.zeroc.com/forums/help-center/3799-how-handle-java-lang-thread-interrupt-safe-way.html


We using the only one code below keeping _selector pipe never broken.
Since we indicate interrupt the current thread, throwing exceptions are very acceptable.
public void
    setInterrupt()
    {
        if(++_interruptCount == 1)
        {
            java.nio.ByteBuffer buf = java.nio.ByteBuffer.allocate(1);
            buf.put(0, (byte)0);
            while(buf.hasRemaining())
            {
                try
                {
[COLOR="Red"]                    Thread.interrupted();[/COLOR]
                    _fdIntrWrite.write(buf);
                }
                catch(java.io.IOException ex)
                {
                    Ice.SocketException se = new Ice.SocketException();
                    se.initCause(ex);
                    throw se;
                }
            }
        }
    }

Will you please review this code, if it works, please commit it into next release.