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

Frank Fock fock at agentpp.com
Wed Apr 6 20:45:28 CEST 2005


Hi,

Yes, there is a bug, but it needs to be fixed differently.
The ThreadPool.stop() method is not supposed to interrupt
the threads of the pool. Instead it should just notify
the TaskManagers about the termination.

The fixed stop() method therefore looks like:

/**
* Stops all threads in this thread pool gracefully. This method will not
* return until all threads have been terminated and joined successfully.
*/
public synchronized void stop() {
stop = true;
for (int i=0; i<taskManagers.size(); i++) {
TaskManager tm = (TaskManager) taskManagers.get(i);
tm.terminate();
synchronized (tm) {
tm.notify();
}
try {
tm.join();
}
catch (InterruptedException ex) {
//ignore
}
}
}

Best regards,
Frank

yielruse wrote:

>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
>
>------------------------------------------------------------------------
>
>_______________________________________________
>SNMP4J mailing list
>SNMP4J at agentpp.org
>http://lists.agentpp.org/mailman/listinfo/snmp4j
>  
>





More information about the SNMP4J mailing list