我有一个进程,应该每5分钟将文件通过ftp发送到远程位置。
它似乎已经卡住了几个小时,没有发送文件。
我取了一个线程转储来查看情况,这是我的线程状态:
"SPPersister" prio=6 tid=0x03782400 nid=0x16c4 runnable [0x0468f000..0x0468fd14]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
- locked <0x239ebea0> (a java.io.InputStreamReader)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
- locked <0x239ebea0> (a java.io.InputStreamReader)
at java.io.BufferedReader.readLine(Unknown Source)
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:294)
at org.apache.commons.net.ftp.FTP._connectAction_(FTP.java:364)
at org.apache.commons.net.ftp.FTPClient._connectAction_(FTPClient.java:540)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:178)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:268)
...
我正在使用以下代码进行连接:
FTPClient client = new FTPClient();
client.setConnectTimeout(10000);
client.connect(host); // <-- stuck here
client.setDataTimeout(20000);
client.setSoTimeout(20000);
client.login(user, pass);
client.changeWorkingDirectory(dir);
连接尝试不应该在10秒内超时吗?
connect
调用之后放置了setDataTimeout
调用,因为我认为它可能像setSoTimeout
调用一样,其文档规定只能在connect
之后使用。现在已经将setDataTimeout
提前,希望这可以解决问题。谢谢。 - pstanton