-
Bug
-
Resolution: Done
-
Major
-
None
-
None
-
False
-
-
False
-
-
Runner calls the stop function after terminating the loop:
public void run() { for(;;) { while(state == State.running) { try { function.run(); // e.g. ServerSocket.accept(), won't react to thread interruption! } catch(Throwable t) { } } synchronized(this) { switch(state) { case stopped: case stopping: if(state == State.stopping) { runStopFuntion(); state(State.stopped); } return; } } } }
Runner.stop() interrupts the thread and relies on run() to execute the stop function. However, this does not work in some cases, e.g. ServerSocket.accept() does not react to interrupts, the the stop function of the runner will not be executed.
Fix: move the calling of the stop function to Runner.stop(), after interrupting the thread:
public synchronized Runner stop() { boolean rc=state(State.stopping); if(!rc) return this; Thread tmp=thread; if(tmp != null) { tmp.interrupt(); if(join_timeout > 0) { try {tmp.join(join_timeout);} catch(InterruptedException e) {} } } synchronized(this) { switch(state) { case stopped: case stopping: if(state == State.stopping) { runStopFuntion(); state(State.stopped); } } } return this; }