Many FileNotFoundExceptions saying "File is opened too much" are displayed in the error log.
Caused by: java.io.FileNotFoundException: /user/local/apache-tomcat-8/**/sample/WEB-INF/**/sample.jar (The file is open too much)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:225)
at java.util.zip.ZipFile.<init>(ZipFile.java:155)
at java.util.jar.JarFile.<init>(JarFile.java:166)
at java.util.jar.JarFile.<init>(JarFile.java:103)
・
・
(abridgement)
・
・
Caused by: java.io.FileNotFoundException: /user/local/apache-tomcat-8/**/sample/WEB-INF/**/sample.jar (The file is open too much)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:225)
at java.util.zip.ZipFile.<init>(ZipFile.java:155)
at java.util.jar.JarFile.<init>(JarFile.java:166)
at java.util.jar.JarFile.<init>(JarFile.java:103)
If you use ProcessBuilder, InputStream, OutputStream, and ErrorStream will be opened without permission in the background, so it seems that you will run out of resources unless you close all streams.
package sample;
import java.io.IOException;
public class ProcessExecutor {
public void execute(String... command) throws IOException {
ProcessBuilder processBuilder = new ProcessBuilder(command);
Process process = processBuilder.start();
process.waitFor();
process.destroy();
}
}
The error was resolved by firmly adding the close process to all streams as shown below.
package sample;
import java.io.IOException;
public class ProcessExecutor {
public void execute(String... command) throws IOException {
ProcessBuilder processBuilder = new ProcessBuilder(command);
Process process = processBuilder.start();
process.waitFor();
//Added later
process.getInputStream().close();
process.getOutputStream().close();
process.getErrorStream().close();
process.destroy();
}
}
Recommended Posts