Java下载海量文件,在一段时间后在互联网网址上显示连接关机/重置

前端之家收集整理的这篇文章主要介绍了Java下载海量文件,在一段时间后在互联网网址上显示连接关机/重置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在构建一个swing应用程序,通过Internet下载多个文件并保存到windows文件共享.我已经使用了SwingWroker,它在内部使用ExecutorService,它在内部对它们进行排队并一次下载10个,但由于某种原因,下载后说2 – 3 MB的文件它会停止并转移到下一个下载文件,它们将被批量下载10个因为SwingWorker已将其固定为Executor Service的线程数.

我必须在Windows文件共享中写这些文件,我使用nio.FileChannels来做到这一点.有50-60个文件,每个重约300MB – 500MB.文件链接位于我通过互联网登录登录页面(带有帖子请求)登录的网页上,然后我在开头指定了CookieHandler.setDefault(新的CookieManager()),所以它对我来说就像一个浏览器.

另一个观察是当我在本地下载它们(而不是Windows服务器共享)时,它们确实可以正常工作.

这是我正在使用的代码

import java.io.File;
import java.io.FileOutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;

import javax.swing.SwingWorker;

public class DownloadProcess extends SwingWorker

这是我在下载5-10分钟后得到的错误堆栈跟踪

/*
  javax.net.ssl.SSLException: Connection has been shutdown: javax.net.ssl.SSLException: java.net.SocketException: Connection reset
  at sun.security.ssl.SSLSocketImpl.checkEOF(Unknown Source)
  at sun.security.ssl.AppInputStream.read(Unknown Source)
  at java.io.BufferedInputStream.read1(Unknown Source)
  at java.io.BufferedInputStream.read(Unknown Source)
  at sun.net.www.MeteredStream.read(Unknown Source)
  at java.io.FilterInputStream.read(Unknown Source)
  at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(Unknown Source)
  at java.nio.channels.Channels$ReadableByteChannelImpl.read(Unknown Source)
  at com.objects.DownloadByteChannel.read(DownloadByteChannel.java:117)
  at sun.nio.ch.FileChannelImpl.transferFromArbitraryChannel(Unknown Source)
  at sun.nio.ch.FileChannelImpl.transferFrom(Unknown Source)
  at com.core.DownloadTask.doInBackground(DownloadTask.java:154)
  at com.core.DownloadTask.doInBackground(DownloadTask.java:59)
  at com.util.ZSwingWorker$1.call(ZSwingWorker.java:286)
  at java.util.concurrent.FutureTask.run(Unknown Source)
  at com.util.ZSwingWorker.run(ZSwingWorker.java:325)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  at java.lang.Thread.run(Unknown Source)
Caused by: javax.net.ssl.SSLException: java.net.SocketException: Connection reset
  at sun.security.ssl.Alerts.getSSLException(Unknown Source)
  at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
  at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
  at sun.security.ssl.SSLSocketImpl.handleException(Unknown Source)
  at sun.security.ssl.SSLSocketImpl.handleException(Unknown Source)
  ... 18 more
Caused by: java.net.SocketException: Connection reset
  at java.net.SocketInputStream.read(Unknown Source)
  at java.net.SocketInputStream.read(Unknown Source)
  at sun.security.ssl.InputRecord.readFully(Unknown Source)
  at sun.security.ssl.InputRecord.read(Unknown Source)
  at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
  at sun.security.ssl.SSLSocketImpl.readDataRecord(Unknown Source)
  ... 18 more
*/

用法

public static void main(String[] args){
  int counter = 1;
  for(String url: urls){  
    new DownloadProcess(url,"\\\\fileshare.server\\xyz"+(counter++)+".txt").execute();
  }      
}
最佳答案
您将不得不更改连接超时服务器端.如果它们具有任何重要性,我会沿途获取一些链接

Modify Session Security settings

Lengthening salesforce session timeout

希望这有帮助,祝你好运,让我知道:)

原文链接:https://www.f2er.com/java/437402.html

猜你在找的Java相关文章