Java file limit on OSX lower than in bash -


i've increased max files limit on macbook pro elasticsearch can work more files, isn't working.

i run command 'ulimit -a' , says "open files" 100,000. can run simple shell script this:

export counter=0 while (true) ; touch "/tmp/foo${counter}" ; export counter=`expr $counter + 1` ; done 

and i'm able create lots of files (over 60,000 before killed script).

however, using java code create randomaccessfiles in empty sub-directory of "/tmp" directory, can make 10,232 files before error: java.io.filenotfoundexception (too many open files). here's java code:

import java.io.*; import java.util.*;  public class max_open_files {     public static void main(string ... args) throws exception {         file testdir = new file("/tmp/tempsubdir");         testdir.mkdirs();          list<file> files = new linkedlist<file>();         list<randomaccessfile> filehandles = new linkedlist<randomaccessfile>();          try {             while (true) {                 file f = new file(testdir, "tmp" + filehandles.size());                 randomaccessfile raf = new randomaccessfile(f, "rw");                 files.add(f);                 filehandles.add(raf);             }         } catch (exception ex) {             system.out.println(ex.getclass() + " " + ex.getmessage());         }          (randomaccessfile raf : filehandles) raf.close()          (file f : files) f.delete();          system.out.println("max open files: " + filehandles.size());     } } 

this java code similar code in elasticsearch tests limit on number of files (in filesystemutils class in maxopenfiles method). elasticsearch has same problem java program has.

why can shell script make many more files java code (mine , elasticsearch's)? why high system limit on number of files not recognized java code?

update may 13 4:50pm cdt: created c version of test program see if limit java-specific , appears so. c version below can open 32,765 files while java code limited 10,232 files.

#include <stdio.h> #include <stdlib.h>  int main(int argc, const char *argv) {     char name[100];     file *fp;     int ndx;      (ndx = 0; ndx < 50000; ndx++) {         sprintf(name, "/tmp/foo%d.txt", ndx);         fp = fopen(name, "w");         if (fp == null) {             fprintf(stdout, "can not create file %d\n", ndx);             return 1;         }         fprintf(fp, "hello %d", ndx);     }      return 0; } 

java virtual machine option reference mac

-xx:- maxfdlimit

directs vm refrain setting file descriptor limit default maximum. default behavior set limit value specified open_max, 10240. normally, maximum number of files process may have open. possible, however, increase limit user-specified value sysctl utility. under such circumstances, may want pass -xx:-maxfdlimit stop java vm restricting number of open files 10240.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -