[SNMP4J] BUG: org.snmp4j.util.ThreadPool can't stop.

yielruse yielruse at 126.com
Wed Apr 6 05:12:08 CEST 2005


hi,
while I use stop() method of org.snmp4j.util.ThreadPool to terminate all threads in the pool, it happens that the threads doesn't die.

Then I check the source code, and found a deadlock in the stop() method. While org.snmp4j.util.ThreadPool.TaskManager waitting task to excute in its run() method, org.snmp4j.util.ThreadPool's stop() method waitting TaskManager thread to die.

The fixture is using the interrupt() method of thread to wake up TaskManager's run() method, just like cancel() in ThreadPool.

So the stop() method should be:
  public synchronized void stop() {
    stop = true;
    for (int i=0; i<taskManagers.size(); i++) {
      TaskManager tm = (TaskManager) taskManagers.get(i);
      tm.terminate();
      tm.interrupt();//add this statement
      try {
        tm.join();
      }
      catch (InterruptedException ex) {
        //ignore
      }
    }
  }
  
Am I right?

forgive my poor Egnlish, cause I am Chinese.

best regards


More information about the SNMP4J mailing list