[ 
https://issues.apache.org/jira/browse/SSHD-935?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16895814#comment-16895814
 ] 

Goldstein Lyor commented on SSHD-935:
-------------------------------------

{quote}Is it possible to get a different connection for every thread?\{quote}

Yes,you can create a session once and then pass it along to each thread - each 
one can create its own SFTP client - however this means that they will work on 
the same user (also make sure you do not close the session until all threads 
are done). If you want each thread to access a different user, then initialize 
a *single* {{SshClient}} instance and have each thread create its own session + 
SFTP - MINA SSHD is thread-safe in this wayt.

> Synchronizing the Apache Mina client connection between thread
> --------------------------------------------------------------
>
>                 Key: SSHD-935
>                 URL: https://issues.apache.org/jira/browse/SSHD-935
>             Project: MINA SSHD
>          Issue Type: Question
>    Affects Versions: 2.2.0
>            Reporter: Zabee Ulla
>            Priority: Major
>
> I have multiple threads accessing a prototype bean 
> SFTPMinaClientConnector.java. Every thread has some random method whose 
> entire job is to connect to a remote machine using the 
> SFTPMinaClientConnector.java, get the job done and disconnect.
> The problem I am facing is connection synchronization. While one thread is 
> still doing some task the other closes it resulting in connection already 
> closed exception. 
> Looks like every thread is using the same connection. 
>  Is it possible to get a different connection for every thread? If so, how 
> can I do that?
>  If not, how can I synchronize the connection? Is there something in Mina 
> APIs that can help in this situation?
> Below is the connect() method from my SFTPMinaClientConnector.java through 
> which every thread goes in
> public void connect(){
> try { 
>  SshClient _client = SshClient.setUpDefaultClient();
>  _client.start();
>  ConnectFuture connectFuture = _client.connect(_username, _host, portNumber);
>  connectFuture.awaitUninterruptibly();
> _session = connectFuture.getSession();
> _session.addPasswordIdentity(_password);
> shellChannel = _session.createShellChannel();
> _session.auth().verify(30000L);
> if (_session.isAuthenticated())
> { LOG.debug("Authentication succeeded. SFTP channel opened and connected."); }
> sftpClient = SftpClientFactory.instance().createSftpClient(_session);
>  }
>  catch (Exception oie) \{ .... }
> }
> Thank you in advance,
> Zabee



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org
For additional commands, e-mail: dev-h...@mina.apache.org

Reply via email to