Suggest Code:
@Override public void run() { while (notTerminated) { Socket sock = null; try { sock = serverSocket.accept(); if (sock != null) { Log.debug("Connect " + sock.toString()); SocketReader reader = connManager.createSocketReader(sock, false, serverPort, true); Thread thread = new Thread(reader, reader.getName()); thread.setDaemon(true); thread.setPriority(Thread.NORM_PRIORITY); thread.start(); } } catch (IOException ie) { if (notTerminated) { Log.error(LocaleUtils .getLocalizedString("admin.error.accept"), ie); } } catch (Throwable e) { Log.error(LocaleUtils.getLocalizedString("admin.error.accept"), e); } finally { if (sock != null) { try { sock.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
This code will be better,When throw Exceptions,close the socket resource,and What do you think of it?