![](/img/trans.png)
[英]Spring Boot - Lot of invalid requests and Socket accept failed java.io.IOException: Too many open files
[英]java.io.IOException: Invalid argument and Too many open files
我使用下载种子的库。 但今天发生了一些错误(日志):
Could not create temp files
java.io.IOException: Invalid argument
at java.io.RandomAccessFile.setLength(Native Method)
at jBittorrentAPI.DownloadManager.checkTempFiles(DownloadManager.java:261)
at jBittorrentAPI.DownloadManager.(DownloadManager.java:108)
at torrentstealer.DownloadTorrent.run(DownloadTorrent.java:65)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Could not create temp files
java.io.IOException: Invalid argument
at java.io.RandomAccessFile.setLength(Native Method)
at jBittorrentAPI.DownloadManager.checkTempFiles(DownloadManager.java:261)
at jBittorrentAPI.DownloadManager.(DownloadManager.java:108)
at torrentstealer.DownloadTorrent.run(DownloadTorrent.java:65)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Could not create temp files
java.io.IOException: Invalid argument
at java.io.RandomAccessFile.setLength(Native Method)
at jBittorrentAPI.DownloadManager.checkTempFiles(DownloadManager.java:261)
at jBittorrentAPI.DownloadManager.(DownloadManager.java:108)
at torrentstealer.DownloadTorrent.run(DownloadTorrent.java:65)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Could not create temp files
java.io.IOException: Invalid argument
at java.io.RandomAccessFile.setLength(Native Method)
at jBittorrentAPI.DownloadManager.checkTempFiles(DownloadManager.java:261)
at jBittorrentAPI.DownloadManager.(DownloadManager.java:108)
at torrentstealer.DownloadTorrent.run(DownloadTorrent.java:65)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Could not create temp files
java.io.FileNotFoundException: /root/TorrentStealer/downloads/MAME - Update ROMs (v0.141 to v0.141u2)/lah_l104.zip (Too many open files)
at java.io.RandomAccessFile.open(Native Method)
at java.io.RandomAccessFile.(RandomAccessFile.java:212)
at jBittorrentAPI.DownloadManager.checkTempFiles(DownloadManager.java:260)
at jBittorrentAPI.DownloadManager.(DownloadManager.java:108)
at torrentstealer.DownloadTorrent.run(DownloadTorrent.java:65)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Could not create temp files
java.io.FileNotFoundException: /root/TorrentStealer/downloads/Degrassi.Junior.High.S01-S03.INTERNAL.DVDRip.XviD-FFNDVD/Degrassi.Junior.High.S01.INTERNAL.DVDRip.XviD-FFNDVDDegrassi.Junior.High.S01E10.INTERNAL.DVDRip.XviD-FFNDVDdegrassi.junior.high.s01e10.internal.dvdrip.xvid-ffndvd.r10 (Too many open files)
at java.io.RandomAccessFile.open(Native Method)
at java.io.RandomAccessFile.(RandomAccessFile.java:212)
at jBittorrentAPI.DownloadManager.checkTempFiles(DownloadManager.java:260)
at jBittorrentAPI.DownloadManager.(DownloadManager.java:108)
at torrentstealer.DownloadTorrent.run(DownloadTorrent.java:65)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Could not create temp files
java.io.FileNotFoundException: /root/TorrentStealer/downloads/MAME - Update ROMs (v0.141 to v0.141u2)/lah_l108.zip (Too many open files)
at java.io.RandomAccessFile.open(Native Method)
at java.io.RandomAccessFile.(RandomAccessFile.java:212)
at jBittorrentAPI.DownloadManager.checkTempFiles(DownloadManager.java:260)
at jBittorrentAPI.DownloadManager.(DownloadManager.java:108)
at torrentstealer.DownloadTorrent.run(DownloadTorrent.java:65)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
等等,日志继续。
我发现这个文件存在,这里是发生错误的代码的一部分:
/** * Check the existence of the files specified in the torrent and if necessary, * create them * * @return int * @todo Should return an integer representing some error message... */ public synchronized int checkTempFiles() { String saveas = Constants.SAVEPATH; // Should be configurable if (this.nbOfFiles > 1) saveas += this.torrent.saveAs + "/"; else { this.torrent.saveAs = this.torrent.name.get(0).toString(); } new File(saveas).mkdirs(); for (int i = 0; i < this.nbOfFiles; i++) { File temp = new File(saveas + ((String) (this.torrent.name.get(i)))); try { this.output_files[i] = new RandomAccessFile(temp, "rw"); this.output_files[i].setLength((Integer)this.torrent.length.get( i)); } catch (IOException ioe) { System.err.println("Could not create temp files"); ioe.printStackTrace(); } } return 0; }
在这里打电话:
// запуск закачки dm.startListening(49152, 65535); dm.startTrackerUpdate();
\n\n
\n\nwhile(true) { if(dm.isComplete()) { break; } try { Thread.sleep(100); } catch(InterruptedException ex) { Logger.getLogger(DownloadTorrent.class.getName()).log(Level.SEVERE, null, ex); } } dm.stopTrackerUpdate(); dm.closeTempFiles();</code></pre>
在这里调用上层代码:ex = Executors.newFixedThreadPool(3);
\n\n for(String torrentFile:torrentFiles)\n {\n ex.submit(new DownloadTorrent(“/ root / TorrentStealer / torrents /”+ torrentFile));\n }\n\n //ожиданиезавершенияпотоковзагрузкифайловторрентов\n ex.shutdown();\n\n 尝试\n {\n ex.awaitTermination(30,TimeUnit.MINUTES);\n }\n catch(InterruptedException ex1)\n {\n Logger.getLogger(Main.class.getName())。log(Level.SEVERE,null,ex1);\n }\n\n ex.shutdownNow(); </代码> </ PRE>\n
这里是修复«打开太多文件»的说明: http : //wiki.magnolia-cms.com/display/WIKI/Too+Many+Open+Files
我设置了999999个最大文件,修复了一段时间的错误,然后设置了9999999进行测试,并没有真正起作用,所有时间错误都发生了。 重新启动服务器后,在运行后的一刻不能打开9999999个文件!
所以男人我不知道该怎么办。 你能帮助我吗?
这是异常发生时打开文件的计数:T217:〜#lsof | wc -l结果是:2708
堆栈跟踪在java.io.RandomAccessFile.setLength()中指示错误,该错误接受long
数据类型。 在您的代码中,您将this.torrent.length.get(i)
的结果this.torrent.length.get(i)
为Integer。
does this.torrent.length.get(i)
返回什么?
将数据从返回转换为Integer时,可能会出现一些缩小的问题,可能会返回负数,导致RandomAccessFile.setLength()
错误输出。
java.io.IOException: Invalid argument
at java.io.RandomAccessFile.setLength(Native Method)
你正在传递负值。 将值转换为long而不是Integer。
java.io.FileNotFoundException: /root/TorrentStealer/downloads/MAME - Update ROMs (v0.141 to v0.141u2)/lah_l104.zip (Too many open files)
您没有关闭文件。 您打开的每个需要关闭的资源必须在finally块中关闭,以确保无法逃脱。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.