我使用Apache的FTPClient將文件上載到FTP服務器。Commons FTPClient - 如果FTP服務器不可用,storeFile()會掛起
但是,即使FTP服務器在我們上傳文件時變得不可用,storeFile()掛起。 storeFile()不取消上傳。
tcpdump的跟蹤:
22:04:29.584767 IP 10.84.78.2> 192.168.114.2:ICMP 10.84.78.2 TCP端口53751不可到達,長度142
有沒有一種方法來設置超時?我已經嘗試在storeFile()之前的connect()和setDataTimeout()之後使用setSoTimeout()。但是這個屬性似乎與這個問題無關。
線程轉儲,FTP服務器後採取的是不可用:
"Thread-1" prio=10 tid=0x00007f1a700f1800 nid=0x479b runnable [0x00007f1a76fea000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
at java.io.BufferedOutputStream.write(Unknown Source)
- locked <0x00000000bb026df8> (a java.io.BufferedOutputStream)
at org.apache.commons.net.io.ToNetASCIIOutputStream.write(ToNetASCIIOutputStream.java:75)
- locked <0x00000000bb028e20> (a org.apache.commons.net.io.ToNetASCIIOutputStream)
at org.apache.commons.net.io.Util.copyStream(Util.java:111)
at org.apache.commons.net.ftp.FTPClient._storeFile(FTPClient.java:653)
at org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:624)
at org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:1976)
at ... (FTPClient.java:103)
at ... (Sender.java:67)
netstat的-anpo輸出:
netstat的-anpo | grep的192
tcp6 0 0 10.84.78.2:9011 192.168.114.2:21 VERBUNDEN 19310/java aus (0.00/0/0)
tcp6 0 201480 10.84.78.2:33088 192.168.114.2:20 VERBUNDEN 19310/java ein (10,26/2/0)
有關在開始storeFile()方法是什麼新線程並在超時時從另一個線程中斷它? – MGorgon