src/main/java/org/java_websocket/server/WebSocketServer.java
public void run() {
		if (!doEnsureSingleThread()) {
			return;
		}
		if (!doSetupSelectorAndServerThread()) {
			return;
		}
		try {
			int iShutdownCount = 5;
			int selectTimeout = 0;
			while ( !selectorthread.isInterrupted() && iShutdownCount != 0) {
				SelectionKey key = null;
				WebSocketImpl conn = null;
				try {
					if (isclosed.get()) {
						selectTimeout = 5;
					}
					int keyCount = selector.select( selectTimeout );
					if (keyCount == 0 && isclosed.get()) {
						iShutdownCount--;
					}
					Set<SelectionKey> keys = selector.selectedKeys();
					Iterator<SelectionKey> i = keys.iterator();

					while ( i.hasNext() ) {
						key = i.next();
						conn = null;
						
						if( !key.isValid() ) {
							continue;
						}

						if( key.isAcceptable() ) {
							doAccept(key, i);
							continue;
						}

						if( key.isReadable() && !doRead(key, i)) {
							continue;
						}

						if( key.isWritable() ) {
							doWrite(key);
						}
					}
					doAdditionalRead();
				} catch ( CancelledKeyException e ) {
					// an other thread may cancel the key
				} catch ( ClosedByInterruptException e ) {
					return; // do the same stuff as when InterruptedException is thrown
				} catch ( IOException ex ) {
					if( key != null )
						key.cancel();
					handleIOException( key, conn, ex );
				} catch ( InterruptedException e ) {
					// FIXME controlled shutdown (e.g. take care of buffermanagement)
					Thread.currentThread().interrupt();
				}
			}
		} catch ( RuntimeException e ) {
			// should hopefully never occur
			handleFatal( null, e );
		} finally {
			doServerShutdown();
		}
	}
public void run() {
		if (!doEnsureSingleThread()) {
			return;
		}
		if (!doSetupSelectorAndServerThread()) {
			return;
		}
		try {
			int iShutdownCount = 5;
			int selectTimeout = 0;
			while ( !selectorthread.isInterrupted() && iShutdownCount != 0) {
				SelectionKey key = null;
				WebSocketImpl conn = null;
				try {
					if (isclosed.get()) {
						selectTimeout = 5;
					}
					int keyCount = selector.select( selectTimeout );
					if (keyCount == 0 && isclosed.get()) {
						iShutdownCount--;
					}
					Set<SelectionKey> keys = selector.selectedKeys();
					Iterator<SelectionKey> i = keys.iterator();

					while ( i.hasNext() ) {
						key = i.next();
						conn = null;
						
						if( !key.isValid() ) {
							continue;
						}

						if( key.isAcceptable() ) {
							doAccept(key, i);
							continue;
						}

						if( key.isReadable() && !doRead(key, i)) {
							continue;
						}

						if( key.isWritable() ) {
							doWrite(key);
						}
					}
					doAdditionalRead();
				} catch ( CancelledKeyException e ) {
					// an other thread may cancel the key
				} catch ( ClosedByInterruptException e ) {
					return; // do the same stuff as when InterruptedException is thrown
				} catch ( IOException ex ) {
					if( key != null )
						key.cancel();
					handleIOException( key, conn, ex );
				} catch ( InterruptedException e ) {
					// FIXME controlled shutdown (e.g. take care of buffermanagement)
					Thread.currentThread().interrupt();
				}
			}
		} catch ( RuntimeException e ) {
			// should hopefully never occur
			handleFatal( null, e );
		} finally {
			doServerShutdown();
		}
	}
Runnable IMPLEMENTATION /////////////////////////////////////////////////