[
https://issues.apache.org/jira/browse/SSHD-225?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13622602#comment-13622602
]
Chris Janicki commented on SSHD-225:
------------------------------------
Resolved, but I had to alter the SSHD code in the three classes where
Executors.newSingleThreadScheduledExecutor() was called. The three classes
are: org.apache.sshd.SshClient, org.apache.sshd.SshServer, and
org.apache.sshd.server.shell.InvertedShellWrapper. As an example, I added code
(see below) to InvertedShellWrapper, then changed two of its constructors to
use Executors.newSingleThreadScheduledExecutor(THREAD_FACTORY) instead of the
no-argument call that creates only non-deamon threads. PLEASE CONSIDER
adopting this change in SSHD to support graceful shutdowns. (Feel free to
close this issue now.)
import java.util.concurrent.ThreadFactory;
/** A custom factory to set a useful name and to ensure the
thread is a daemon */
private static final ThreadFactory THREAD_FACTORY = new
ThreadFactory()
{
private int executorCount = 0;
@Override public Thread newThread(Runnable r)
{
executorCount++;
Thread t = new Thread(r);
t.setName("InvertedShellWrapper Executor
#"+executorCount);
t.setDaemon(true);
return t;
}
};
> A non-deamon thread pool prevents graceful JVM exit
> ---------------------------------------------------
>
> Key: SSHD-225
> URL: https://issues.apache.org/jira/browse/SSHD-225
> Project: MINA SSHD
> Issue Type: Bug
> Affects Versions: 0.8.0
> Environment: Apple Java v. 1.6.0
> Reporter: Chris Janicki
>
> When embedded in my app, the following SSHD thread remains running and
> prevents my app from exiting gracefully (by allowing the JVM to automatically
> shutdown when only deamon threads remain). I call sshd.stop(true), but this
> thread still remains. Note however, than it seems to die itself after
> several minutes (10+). Then my app successfully exits.
> "pool-6-thread-1" prio=5 tid=102821800 nid=0x10e941000 waiting on condition
> [10e940000]
> java.lang.Thread.State: WAITING (parking)
> at sun.misc.Unsafe.park(Native Method)
> - parking to wait for <7eedb8190> (a
> java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
> at java.util.concurrent.locks.LockSupport.park(LockSupport.java:156)
> at
> java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1987)
> at
> java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:399)
> at
> java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:957)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:917)
> at java.lang.Thread.run(Thread.java:680)
> I tried the following to replace the executor's ThreadFactory with my own
> (this) that calls setDaemon(true) on the generated thread, but that didn't
> work for some reason… The thread in the dump was still not marked daemon, so
> maybe I'm looking at the wrong area.
> ScheduledExecutorService executor =
> Executors.newSingleThreadScheduledExecutor(this);
> sshd.setScheduledExecutorService(executor, true);
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira