Java FTP无法在SwingWorker Thread中运行

时间:2012-05-04 06:03:58

标签: java multithreading swing swingworker ftp4j

我有一个简单的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中并将其放在自己的类中,它运行得很完美。

1 个答案:

答案 0 :(得分:0)

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