selectedConnection.doWrite();
try { selectedConnection.doWrite(); } catch (IOException ioe) {  if (mLog.isDebugEnabled()) { mLog.debug("exception writing, closing connection", ioe); } selectedConnection.closeNow(); }
    private void serverLoop() {        while (true) {            synchronized (mServerThreadTasks) {                if (mLog.isDebugEnabled()) mLog.debug("running " + mServerThreadTasks.size() + " server thread tasks");                for (Iterator taskIter = mServerThreadTasks.iterator(); taskIter.hasNext(); taskIter.remove()) {                    Runnable task = (Runnable) taskIter.next();                    try {                        task.run();                    } catch (Throwable e) {                        mLog.warn("ignoring exception that occurred while running server thread tasks", e);                    }                }            }                        synchronized (this) {                if (mShutdownRequested) {                    break;                }            }            int readyCount = 0;            try {                if (mLog.isDebugEnabled()) mLog.debug("entering select");                readyCount = mSelector.select();            } catch (IOException ioe) {                mLog.warn("OzServer IOException in select", ioe);            }            if (mLog.isDebugEnabled()) mLog.debug("selected readyCount=" + readyCount);            if (readyCount == 0) {                continue;            }                        Iterator iter = mSelector.selectedKeys().iterator();            while (iter.hasNext()) {                SelectionKey readyKey = (SelectionKey) iter.next();                iter.remove();                OzConnection selectedConnection = null;                 if (readyKey.attachment() != null && readyKey.attachment() instanceof OzConnection) {                    selectedConnection = (OzConnection)readyKey.attachment();                    selectedConnection.addToNDC();                }                try {                    synchronized (readyKey) {                        OzConnection.logKey(mLog, readyKey, "ready key");                    }                                        if (!readyKey.isValid()) {                        continue;                    }                                        if (readyKey.isAcceptable()) {                        Socket newSocket = mServerSocket.accept();                        SocketChannel newChannel = newSocket.getChannel();                         newChannel.configureBlocking(false);                        selectedConnection= new OzConnection(OzServer.this, newChannel);                    }                                        if (readyKey.isReadable()) {                        selectedConnection.doRead();                    }                                        if (readyKey.isWritable()) {                        selectedConnection.doWrite();                    }                } catch (Throwable t) {                    mLog.warn("ignoring exception that occurred while handling selected key", t);                    if (selectedConnection != null) {                        selectedConnection.closeNow();                    }                } finally {                    if (selectedConnection != null) {                        selectedConnection.clearFromNDC();                    }                }                            } /* end of ready keys loop */            if (mLog.isDebugEnabled()) mLog.debug("processed " + readyCount + " ready keys");        }                assert(mShutdownRequested);        mLog.info("shutting down thread pool");        mPooledExecutor.shutdownNow();        try {            mLog.info("waiting for thread pool to shutdown");            mPooledExecutor.awaitTerminationAfterShutdown(10*1000);        } catch (InterruptedException ie) {            mLog.warn("unexpected exception when waiting for shutdown");        }        mLog.info("done waiting for thread pool to shutdown");        mLog.info("closing all selection keys");        Set keys = mSelector.keys();        for (Iterator iter = keys.iterator(); iter.hasNext();) {            SelectionKey key = (SelectionKey) iter.next();            try {                key.channel().close();            } catch (IOException ioe) {                mLog.info("exception closing selection key", ioe);            }        }        try {            mSelector.close();        } catch (IOException ioe) {            mLog.warn("unexpected exception when closing selector");        }        mLog.info("closed selector");        mLog.info("initiating buffer pool destroy");        mBufferPool.destroy();        synchronized (mShutdownCompleteCondition) {            mShutdownComplete = true;            mShutdownCompleteCondition.notify();        }    }