java.io.IOException:无效参数和打开文件太多

发布于 2024-11-09 02:13:27 字数 8836 浏览 0 评论 0原文

我使用下载种子的库。但今天发生了一些错误(日志): <代码>

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)
And so on, log continues. I found that this file exists and here is a part of code where error happens:
    /**
     * 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;
    }
Which called here:
        // запуск закачки
        dm.startListening(49152, 65535);
        dm.startTrackerUpdate();

    while(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);

for(String torrentFile : torrentFiles) { ex.submit(new DownloadTorrent("/root/TorrentStealer/torrents/" + torrentFile)); } // ожидание завершения потоков загрузки файлов торрентов ex.shutdown(); try { ex.awaitTermination(30, TimeUnit.MINUTES); } catch(InterruptedException ex1) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex1); } ex.shutdownNow();</code></pre>

以下是修复“打开文件过多”的说明: http://wiki.magnolia-cms.com/display/WIKI /Too+Many+Open+Files

我设置了 999999 个最大文件,修复了一段时间的错误,然后设置 9999999 进行测试,并没有真正起作用,总是发生错误。服务器重启后运行后一瞬间不可能有9999999个打开的文件!

所以男人们我不知道该怎么办。你能帮助我吗?

以下是发生异常时打开文件的计数: T217:~# lsof |厕所-l 结果是:2708

I use library which download torrents. But today some error happened (log):

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)

And so on, log continues. I found that this file exists and here is a part of code where error happens:

    /**
     * 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;
    }

Which called here:

        // запуск закачки
        dm.startListening(49152, 65535);
        dm.startTrackerUpdate();

    while(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>

And upper code called here:

ex = Executors.newFixedThreadPool(3);

for(String torrentFile : torrentFiles)
{
ex.submit(new DownloadTorrent("/root/TorrentStealer/torrents/" + torrentFile));
}

// ожидание завершения потоков загрузки файлов торрентов
ex.shutdown();

try
{
ex.awaitTermination(30, TimeUnit.MINUTES);
}
catch(InterruptedException ex1)
{
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex1);
}

ex.shutdownNow();</code></pre>

Here is description of fixing «Too many open files»:
http://wiki.magnolia-cms.com/display/WIKI/Too+Many+Open+Files

I set up 999999 max files, that fixed error for some time, then set up 9999999 for testing, not really works, all the time error happens. There can't be 9999999 opened files at the one moment after running when the server has been rebooted!

So men I don't know what to do. Can you help me?

Here is count of opened files when exceptions happened:
T217:~# lsof | wc -l
Result is: 2708

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倦话 2024-11-16 02:13:27

堆栈跟踪指示 java.io.RandomAccessFile.setLength() 处存在错误,该错误接受 long 数据类型。在您的代码中,您将 this.torrent.length.get(i) 的结果转换为 Integer。

this.torrent.length.get(i) 返回什么?

当您将返回的数据转换为整数时,可能会出现一些缩小尺寸的问题,可能会返回负数,从而导致 RandomAccessFile.setLength() 出错。

The stacktrace indicated error at java.io.RandomAccessFile.setLength() which accept a long data type. In your code you cast the result of this.torrent.length.get(i) to Integer.

What does this.torrent.length.get(i) return?

it could be some downsizing issue when you convert data from the return to Integer, probably returning negative number which caused RandomAccessFile.setLength() to error out.

谜泪 2024-11-16 02:13:27
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 块中关闭,以确保没有逃逸。

java.io.IOException: Invalid argument
    at java.io.RandomAccessFile.setLength(Native Method)

You are passing a negative value. Cast the value to a long not an Integer.

java.io.FileNotFoundException: /root/TorrentStealer/downloads/MAME - Update ROMs (v0.141 to v0.141u2)/lah_l104.zip (Too many open files)

You aren't closing your files. Every resource you open that needs closing must be closed, in a finally block to ensure there is no escape.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文