[英]What is the meaning of different timeout properties of Apache FTPClient (and DefaultFtpSessionFactory in Spring)?
There are following timeout properties used for FTP communication:有以下用于 FTP 通信的超时属性:
Could you explain to Java/Kotlin developer why to set them and what bad things could happen if you do not set them?您能否向 Java/Kotlin 开发人员解释为什么要设置它们以及如果不设置它们会发生什么不好的事情?
To add some context: My server app needs to connect to FTP and list/upload/download/delete files.添加一些上下文:我的服务器应用程序需要连接到 FTP 并列出/上传/下载/删除文件。 I would like to be sure my attempts to connect or transfer file won't hang forever in case something goes wrong.
我想确保我连接或传输文件的尝试不会永远挂起,以防出现问题。
All those properties from the AbstractFtpSessionFactory
are propagated down to an FTPClient
: AbstractFtpSessionFactory
中的所有这些属性都向下传播到FTPClient
:
if (this.connectTimeout != null) {
client.setConnectTimeout(this.connectTimeout);
}
if (this.defaultTimeout != null) {
client.setDefaultTimeout(this.defaultTimeout);
}
if (this.dataTimeout != null) {
client.setDataTimeout(this.dataTimeout);
}
The connectTimeout
over there has a default value as private static final int DEFAULT_CONNECT_TIMEOUT = 60000;
那边的
connectTimeout
有一个默认值private static final int DEFAULT_CONNECT_TIMEOUT = 60000;
. . So, it is OK to miss it.
所以,错过它是可以的。 Yes, this one is used when we create a
Socket
via connect()
: _socket_.connect(new .netSocketAddress(host, port), connectTimeout);
是的,当我们通过
connect()
创建Socket
时会用到这个: _socket_.connect(new .netSocketAddress(host, port), connectTimeout);
The defaultTimeout
is propagated down to _socket_.setSoTimeout(_timeout_);
defaultTimeout
向下传播到_socket_.setSoTimeout(_timeout_);
which has an effect on socket read operations.这对套接字读取操作有影响。 See
Socket.setSoTimeout()
JavaDocs.请参阅
Socket.setSoTimeout()
JavaDocs。 Yes, its default value is 0
.是的,它的默认值为
0
。 So, also OK to miss its configuration.所以,也可以错过它的配置。
The dataTimeout
is used for the server Socket
created in a ACTIVE_LOCAL_DATA_CONNECTION_MODE
for similar setSoTimeout()
option. dataTimeout
用于在ACTIVE_LOCAL_DATA_CONNECTION_MODE
中创建的服务器Socket
,用于类似的setSoTimeout()
选项。 Default is the same: 0 - infinite wait for read operation answer.默认值相同:0 - 无限等待读取操作应答。
I derived all of that from Apache Commons Net source code.我从 Apache Commons Net 源代码中得出所有这些。
Doesn't look like the project provides some docs on the matter by itself: https://commons.apache.org/proper/commons.net/看起来该项目本身并不提供有关此事的一些文档: https://commons.apache.org/proper/commons.net/
So, yeah, a rule of thumb: always configure those props with a reasonable values.所以,是的,一条经验法则:始终使用合理的值配置这些道具。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.