1

我有一个简单的 GUI 程序,它与数据库进行一些交互,然后一旦完成 ftps 将一些文件上传到服务器。在我添加 SwingWorker 线程以保持 GUI 响应之前,这一直很有效。

如果我把它放在它的独立项目中,我正在使用的代码可以正常工作,但是在这个项目(SwingWorker 线程)中它给了我以下错误:

java.net.SocketException: Software caused connection abort: recv failed

at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
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)
at sun.nio.cs.StreamDecoder.read0(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at it.sauronsoftware.ftp4j.NVTASCIIReader.readLine(NVTASCIIReader.java:105)
at it.sauronsoftware.ftp4j.FTPCommunicationChannel.read(FTPCommunicationChannel.java:142)
at it.sauronsoftware.ftp4j.FTPCommunicationChannel.readFTPReply(FTPCommunicationChannel.java:187)
at it.sauronsoftware.ftp4j.FTPClient.openActiveDataTransferChannel(FTPClient.java:3511)
at it.sauronsoftware.ftp4j.FTPClient.openDataTransferChannel(FTPClient.java:3475)
at it.sauronsoftware.ftp4j.FTPClient.upload(FTPClient.java:2641)
at it.sauronsoftware.ftp4j.FTPClient.upload(FTPClient.java:2550)
at it.sauronsoftware.ftp4j.FTPClient.upload(FTPClient.java:2421)
at GUI$MatchFiles.doInBackground(GUI.java:1602)
at GUI$MatchFiles.doInBackground(GUI.java:1)
at javax.swing.SwingWorker$1.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at javax.swing.SwingWorker.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

有任何想法吗?

编辑:我假设你的意思是这样的?请注意这是一个非常精简的版本,我已经删除了很多多余的代码。我看不出有任何影响。

class Worker extends SwingWorker<Integer, Integer>{
    protected Integer doInBackground() throws Exception{
        FTPClient client = new FTPClient();
        client.connect(url);
        client.login(username, password);
        client.setPassive(false);
        client.changeDirectory(uploaddirectory);
        client.upload(new File(fileuploadpath));
        client.disconnect(true);
    }

    protected void done() {                
        System.out.println("Done");                 
    }
}

如前所述,我将这段代码放在 swingworker 中并将其放入自己的类中,它运行完美。

4

1 回答 1

0

看起来您的套接字已被防火墙或防病毒软件切断...尝试禁用防火墙和防病毒软件并重新运行您的程序...

于 2012-05-04T06:40:13.467 回答