CounterWithWait { public boolean start() throws InterruptedException { Thread threadWord = new Thread(word.new TokenThread()); Thread threadSpace = new Thread(space.new TokenThread()); this.info(String.format("%s %s",Thread.currentThread().getName()," start"),System.currentTimeMillis()); threadSpace.start(); threadSpace.join(); threadWord.start(); threadWord.join(); while(threadSpace.isAlive() || threadWord.isAlive()){ if(((System.currentTimeMillis() - this.startTime) > 1000) && (threadSpace.isAlive() || threadWord.isAlive())){ this.info(String.format("",Thread.currentThread().getName()," tired of waiting"),System.currentTimeMillis()); if(threadSpace.isAlive()){ threadSpace.interrupt(); if(threadSpace.isInterrupted()){ throw new InterruptedException(); } } if(threadWord.isAlive()){ threadWord.interrupt(); if(threadWord.isInterrupted()){ throw new InterruptedException(); } } } } this.info(String.format("%s %s ",Thread.currentThread().getName()," finally job"),System.currentTimeMillis()); return true; } CounterWithWait(long startTime, TokenCounter word, TokenCounter space); String info(String info,final long currentTime); boolean start(); static void main(String[] args);  }
@Test public void start() throws Exception { }