public void run() {    while (true) {
      try {        selector.select();
        Set selected = selector.selectedKeys();
        Iterator it = selected.iterator();
        //Selector如果发现channel有OP_ACCEPT或READ事件发生,下列遍历就会进行。
        while (it.hasNext())          //来一个事件 第一次触发一个accepter线程
          //以后触发SocketReadHandler
          dispatch( (SelectionKey) (it.next()));
        selected.clear();
      } catch (IOException ex) {
        Debug.logError("reactor error" + ex, module);
      }    }
  }  //运行Acceptor或SocketReadHandler
  private void dispatch(SelectionKey key) {
    Runnable r = (Runnable) (key.attachment());
    if (r != null) {      r.run();
    }
  }在dispatch中的run是怎么运行的?
是调用上面public void run()吗? 
帮我看看呀

解决方案 »

  1.   

    问题不是很清楚啊,两个方法是在一个类中吗?
    如果是,那么就不是调用上面的run()。况且启动一个线程是用start()
      

  2.   

    是在一个类中,此类run目的是选择合适的key交给dispacth,由dispacth作相应调用
      

  3.   

    我这样理解不知对不?关键是attachment返回对象,这个对象根据其型别调用其相应run.各位说下是否这样还是有其他理解.