@Override
	public void run() {
		System.out.println("start listening");

		SelectionKey key = null;
		while (true) {

			try {
				//
				int num = selector.select();

				if (num > 0) {
					Set selectedKeys = selector.selectedKeys();
					Iterator it = selectedKeys.iterator();

					while (it.hasNext()) {
						//
						key = (SelectionKey) it.next();
						it.remove();

						if (!key.isValid()) {
							continue;
						}
						if (key.isAcceptable()) {
							accept(key);
						} else if (key.isReadable()) {
							read(key);
							key.cancel();
						} else if (key.isWritable()) {
							write(key);
							key.cancel();
						}
					}
				} else {
					//register "write" event
					dealRegisterQueue();
				}

			} catch (Exception e) {
				if(key != null){
					key.cancel();
					Util.closeQuietly(key.channel());
				}
				logger.error("closed error",e);
			}
		}
	}