-
Type: Bug
-
Resolution: Done
-
Priority: Critical - P2
-
None
-
Affects Version/s: 2.5.3
-
Component/s: API
-
Environment:Linux 64 Bit, Eclipse Helios Service Release 2
I'm getting the following error:
<<<
java.io.FileNotFoundException: /home/user/image.jpg (Too many open files)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at com.mongodb.gridfs.GridFS.createFile(GridFS.java:239)
<<<
I'm migrating a Oracle DB to MongoDB. For the work I'm using several threads which reads Orcale and put the information to MongoDB.
Therefor im crawling a filesystem for different files, which need to be inserted in MongoDB.
My Code - within the thread - where I'm receiving the exception:
File file = new File(filePath);
GridFSInputFile inputFile = null;
try {
if(!file.exists())
inputFile = grid.createFile(file);
inputFile.put("media", "file");
inputFile.save();
} catch (IOException e)
Is seams that GridFSInputFile is creating an InputStream and after saving the file, the InputStream isn't closed nor is there a method to close the stream.
How should this be handled?
My workaround is:
File file = new File(filePath);
GridFSInputFile inputFile = null;
try {
if(!file.exists())
final InputStream is = new FileInputStream(file);
try
finally
{ is.close(); }
} catch (IOException e)