本文整理汇总了Java中com.jcraft.jsch.Session.setDaemonThread方法的典型用法代码示例。如果您正苦于以下问题:Java Session.setDaemonThread方法的具体用法?Java Session.setDaemonThread怎么用?Java Session.setDaemonThread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jcraft.jsch.Session
的用法示例。
在下文中一共展示了Session.setDaemonThread方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import com.jcraft.jsch.Session; //导入方法依赖的package包/类
@Override
public Session create(ConnectionDetails connectionDetails) throws Exception {
log.debug("Creating session for "+connectionDetails);
Session session = null;
try {
byte[] privateKey = connectionDetails.getPrivateKey();
if (privateKey != null) {
jsch.addIdentity(connectionDetails.getUsername(), privateKey, null, connectionDetails.getPassword().getBytes());
}
session = jsch.getSession(connectionDetails.getUsername(), connectionDetails.getHost(), connectionDetails.getPort());
session.setPassword(connectionDetails.getPassword());
if (!hostKeyValidation) {
session.setConfig("StrictHostKeyChecking", "no");
}
session.setDaemonThread(true);
session.connect();
} catch (Exception e) {
log.error("Failed to connect to "+connectionDetails);
throw e;
}
return session;
}
示例2: main
import com.jcraft.jsch.Session; //导入方法依赖的package包/类
public static void main( String[] args )
{
String hostname = null;
int port = 22;
String username = null;
String password = null;
int timeout = 20000;
Properties config = new java.util.Properties();
config.put( "StrictHostKeyChecking", "no" );
for ( int i = 0; i < args.length; i++ )
{
if ( args[i].equalsIgnoreCase( "-host" ) )
{
hostname = args[i + 1];
i++;
}
else if ( args[i].equalsIgnoreCase( "-port" ) )
{
port = Integer.parseInt( args[i + 1] );
i++;
}
else if ( args[i].equalsIgnoreCase( "-username" ) )
{
username = args[i + 1];
i++;
}
else if ( args[i].equalsIgnoreCase( "-password" ) )
{
password = args[i + 1];
i++;
}
}
if ( hostname == null )
{
logger.error( "Hostname cannot be null." );
}
else if ( username == null )
{
logger.error( "Username cannot be null." );
}
else if ( password == null )
{
logger.error( "Password cannot be null." );
}
long start = System.currentTimeMillis();
logger.info( "Start of processing." );
JSch jsch = new JSch();
try
{
Session session = jsch.getSession( username, hostname, port );
session.setPassword( password );
session.setDaemonThread( true );
session.setConfig( config );
logger.info( "Session default timeout " + session.getTimeout() );
session.setTimeout( timeout );
logger.info( "Session created after " + ( System.currentTimeMillis() - start ) / 1000.0 + " seconds." );
session.connect();
logger.info( "Connection established after " + ( System.currentTimeMillis() - start ) / 1000.0
+ " seconds." );
}
catch ( JSchException e )
{
logger.info( "Connection aborted after " + ( System.currentTimeMillis() - start ) / 1000.0 + " seconds." );
logger.error( "Received exception.", e );
}
}
示例3: createJschSession
import com.jcraft.jsch.Session; //导入方法依赖的package包/类
private Session createJschSession() throws JSchException {
Session session;
JSch jsch = new JSch();
session = jsch.getSession(target.getLoginName(), target.getHost(),
target.getPort());
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword(target.getLoginPassword());
session.setDaemonThread(true);
session.connect(60000); // making a connection with 60s timeout.
return session;
}