Skip to content

Too many open files -> Issue #123

Answered by ksclarke
andybuki asked this question in Q&A
Jun 12, 2021 · 2 comments · 6 replies
Discussion options

You must be logged in to vote

Looking at the above example I'd say it's because you're opening a file stream at new FileInputStream(file) (inside the loop) but never closing it, so running out of file handles.

As a test, I used the following Bash script to create 5000 test JSON files:

#! /bin/bash

mkdir -p /tmp/test /tmp/test-out

for i in $(seq 1 5000);
do
  cp src/test/resources/cookbook/0001-mvm-image.json "/tmp/test/${i}.json";
done

Then I use the following code to read and write them:

final Manifestor manifestor = new Manifestor();

Files.list(Path.of("/tmp/test")).forEach(path -> {
    final File oldFile = path.toFile();
    final File newFile = new File("/tmp/test-out/" + FileUtils.stripExt(oldFile) + "-new.j…

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
1 reply
@andybuki
Comment options

Comment options

You must be logged in to vote
5 replies
@andybuki
Comment options

@ksclarke
Comment options

@andybuki
Comment options

@ksclarke
Comment options

@andybuki
Comment options

Answer selected by ksclarke
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants