I am using MINA 1.1.2 snapshot in an OSGi environment. OS: debian uname -r: 2.6.15-1-686-smp JVM version is 1.5.0_06-b05
In a bundle that contains client code, the class Channel's lifecycle is in sync with the bundle lifecycle. That is, if I stop the bundle, then Channel's dispose() method is called. e.g. class Channel { ExecutorService m_executor; SocketConnector m_connector; public Channel( Executor executor, ... ) { m_executor = executor; m_connector = new SocketConnector( Runtime.getRuntime().availableProcessors() + 1, executor ); ... etc ... } public void dispose() { m_executor.shutdownNow(); m_connector.setWorkerTimeout( 0 ); } } But I have noticed that when I stopped the bundle, some SocketConnector related threads are still alive. Could someone verify that my dispose() method is sufficient ? Perhaps I'm missing something. Here are a snippet from a thread dump of the OSGi container (with the bundle stopped):- ==> This PooledByteBufferExpirer-0 never seems to die. But I think it's benign and would only die during container restart. Thread 8086: (state = BLOCKED) - java.lang.Thread.sleep(long) @bci=0 (Interpreted frame) - org.apache.mina.common.PooledByteBufferAllocator$Expirer.run() @bci=10, line=249 (Compiled frame) ==> This refers to SocketConnectorIoProcessor-3.0. It only dies if the server is shutdowned. Thread 13366: (state = IN_NATIVE) - sun.nio.ch.PollArrayWrapper.poll0(long, int, long) @bci=0 (Compiled frame; information may be imprecise) - sun.nio.ch.PollArrayWrapper.poll(int, int, long) @bci=13, line=100 (Compiled frame) - sun.nio.ch.SelectorImpl.lockAndDoSelect(long) @bci=37, line=69 (Compiled frame) - sun.nio.ch.SelectorImpl.select(long) @bci=30, line=80 (Compiled frame) - org.apache.mina.util.NamePreservingRunnable.run() @bci=11, line=39 (Interpreted frame) - java.util.concurrent.ThreadPoolExecutor$Worker.runTask(java.lang.Runnable) @bci=44, line=650 (Interpreted frame) - java.util.concurrent.ThreadPoolExecutor$Worker.run() @bci=28, line=675 (Interpreted frame) - java.lang.Thread.run() @bci=11, line=595 (Interpreted frame) ==> This refers to AnonymousIoService-?. And I have tons of them hanging around. Thread 8091: (state = BLOCKED) - sun.misc.Unsafe.park(boolean, long) @bci=0 (Interpreted frame) - java.util.concurrent.locks.LockSupport.park() @bci=5, line=118 (Interpreted frame) - java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await() @bci=41, line=1767 (Interpreted frame) - java.util.concurrent.LinkedBlockingQueue.take() @bci=29, line=359 (Interpreted frame) - java.util.concurrent.ThreadPoolExecutor.getTask() @bci=47, line=470 (Interpreted frame) - java.util.concurrent.ThreadPoolExecutor$Worker.run() @bci=18, line=674 (Interpreted frame) - java.lang.Thread.run() @bci=11, line=595 (Interpreted frame) Thanks chihiro -- View this message in context: http://www.nabble.com/How-to-terminate-all-threads-in-SocketConnector---tf4631786s16868.html#a13226239 Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.