@Test public void testMultipleStarts() { try { Communicator server = new ServerCommunicator(45756); Communicator client = new ClientCommunicator("0.0.0.0", 45756); server.start(); server.start(); Thread.sleep(100); client.start(); client.start(); server.start(); client.start(); } catch (InterruptedException e) { e.printStackTrace(); } }
@Override public void start() { queue.clear(); try { mainThread.start(); } catch (IllegalThreadStateException e) { if (!mainThread.isAlive()) { mainThread = new Thread(this, getClass().getSimpleName()); mainThread.start(); } else { log("Thread " + mainThread.getName() + " is already running."); } } }
AbstractCommunicator implements Communicator { @Override public void start() { queue.clear(); try { mainThread.start(); } catch (IllegalThreadStateException e) { if (!mainThread.isAlive()) { mainThread = new Thread(this, getClass().getSimpleName()); mainThread.start(); } else { log("Thread " + mainThread.getName() + " is already running."); } } } }
AbstractCommunicator implements Communicator { @Override public void start() { queue.clear(); try { mainThread.start(); } catch (IllegalThreadStateException e) { if (!mainThread.isAlive()) { mainThread = new Thread(this, getClass().getSimpleName()); mainThread.start(); } else { log("Thread " + mainThread.getName() + " is already running."); } } } protected  AbstractCommunicator(int port); }
AbstractCommunicator implements Communicator { @Override public void start() { queue.clear(); try { mainThread.start(); } catch (IllegalThreadStateException e) { if (!mainThread.isAlive()) { mainThread = new Thread(this, getClass().getSimpleName()); mainThread.start(); } else { log("Thread " + mainThread.getName() + " is already running."); } } } protected  AbstractCommunicator(int port); @Override void run(); @Override void setState(MopedState state); @Override void setValue(MopedDataType type, int value); @Override void addListener(CommunicationListener cl); @Override void start(); @Override void stop(); boolean isRunning(); boolean isLoggingEnabled(); void enableLogging(); void disableLogging(); }
AbstractCommunicator implements Communicator { @Override public void start() { queue.clear(); try { mainThread.start(); } catch (IllegalThreadStateException e) { if (!mainThread.isAlive()) { mainThread = new Thread(this, getClass().getSimpleName()); mainThread.start(); } else { log("Thread " + mainThread.getName() + " is already running."); } } } protected  AbstractCommunicator(int port); @Override void run(); @Override void setState(MopedState state); @Override void setValue(MopedDataType type, int value); @Override void addListener(CommunicationListener cl); @Override void start(); @Override void stop(); boolean isRunning(); boolean isLoggingEnabled(); void enableLogging(); void disableLogging();  }