public void run() {
            Selector selector = SocketConnector.this.selector;
            for (;;) {
                try {
                    int nKeys = selector.select(1000);

                    registerNew();

                    if (nKeys > 0) {
                        processSessions(selector.selectedKeys());
                    }

                    processTimedOutSessions(selector.keys());

                    if (selector.keys().isEmpty()) {
                        if (System.currentTimeMillis() - lastActive > workerTimeout * 1000L) {
                            synchronized (lock) {
                                if (selector.keys().isEmpty()
                                        && connectQueue.isEmpty()) {
                                    worker = null;
                                    try {
                                        selector.close();
                                    } catch (IOException e) {
                                        ExceptionMonitor.getInstance()
                                                .exceptionCaught(e);
                                    } finally {
                                        SocketConnector.this.selector = null;
                                    }
                                    break;
                                }
                            }
                        }
                    } else {
                        lastActive = System.currentTimeMillis();
                    }
                } catch (IOException e) {
                    ExceptionMonitor.getInstance().exceptionCaught(e);

                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e1) {
                        ExceptionMonitor.getInstance().exceptionCaught(e1);
                    }
                }
            }
        }