/** * Closes the socket and stops the listener thread. * * @throws IOException */ public void close() throws IOException { boolean interrupted = false; WorkerTask l = listener; if (l != null) { l.terminate(); l.interrupt(); if (socketTimeout > 0) { try { l.join(); } catch (InterruptedException ex) { interrupted = true; logger.warn(ex); } } listener = null; } DatagramSocket closingSocket = socket; if ((closingSocket != null) && (!closingSocket.isClosed())) { closingSocket.close(); } socket = null; if (interrupted) { Thread.currentThread().interrupt(); } }
/** * Sets the name of the listen thread for this UDP transport mapping. This method has no effect, * if called before {@link #listen()} has been called for this transport mapping. * * @param name the new thread name. * @since 1.6 */ public void setThreadName(String name) { WorkerTask lt = listener; if (lt instanceof Thread) { ((Thread) lt).setName(name); } }
/** * Changes the priority of the listen thread for this UDP transport mapping. This method has no * effect, if called before {@link #listen()} has been called for this transport mapping. * * @param newPriority the new priority. * @see Thread#setPriority(int) * @since 1.2.2 */ public void setPriority(int newPriority) { WorkerTask lt = listener; if (lt instanceof Thread) { ((Thread) lt).setPriority(newPriority); } }