我正在使用JSch库列出并从SFTP服务器下载文件。
在JSch ChannelSftp操作上配置超时
Channel channel = this.session.openChannel(SFTP_CHANNEL_NAME);
channel.connect();
sftpChannel = (ChannelSftp) channel;
Vector listing = sftpChannel.ls("*");
在调用ls
时,应用程序线程有时会卡住。
线程转储 -
Thread 15108: (state = BLOCKED)
java.lang.Object.wait(long) @bci=0 (Compiled frame; information may be imprecise)
java.io.PipedInputStream.read() @bci=142, line=310 (Compiled frame)
java.io.PipedInputStream.read(byte[], int, int) @bci=43, line=361 (Compiled frame)
com.jcraft.jsch.ChannelSftp.fill(byte[], int, int) @bci=17, line=2527 (Compiled frame)
com.jcraft.jsch.ChannelSftp.header(com.jcraft.jsch.Buffer, com.jcraft.jsch.ChannelSftp$Header) @bci=12, line=2553 (Interpreted frame)
com.jcraft.jsch.ChannelSftp.ls(java.lang.String) @bci=298, line=1424 (Interpreted frame)
是否有对ls
等方法配置超时的方法吗?我在channel.connect(timeout)
上看到了设置超时,但这只会在连接到远程服务器时设置超时。
以我的版本,这是0.1.53,参数超时'如在该文档中指定setServerAliveInterval'被解释,在**毫秒**。 – bskp 2017-06-22 06:49:27