What is this?
This little Java agent is a tool that keeps track of where/when/who opened files in your JVM. You can have the agent trace these operations to find out about the access pattern or handle leaks, and dump the list of currently open files and where/when/who opened them.
In addition, upon "too many open files" exception, this agent will dump the list, allowing you to find out where a large number of file descriptors are in use.
For a long running application, you can have it run a mini HTTP server to access the information on demand. This tool can be also loaded as a regular dependency jar and the list of the table can be programmatically accessed.
Without any option, this tool silently records file open/close operations and upon "too many open files" exception, the table will be dumped to stderr.
$ java -javaagent:path/to/file-leak-detector.jar ...your usual Java args follows...
There are several options you can pass to the agent. For example, to dump the open file handles when the total number reaches 200, you can do the following:
$ java -javaagent:path/to/file-leak-detector.jar=threshold=200 ...your usual Java args follows...
Or have it run a mini HTTP server so that you can access the information from your browser, do the followind and open http://localhost:19999/:
$ java -javaagent:path/to/file-leak-detector.jar=http=19999 ...your usual Java args follows...
Use the help option to see the help screen for the complete list of options.
$ java -javaagent:path/to/file-leak-detector.jar=help
Attaching after VM startup
When run as a regular jar file, this tool can be used to attach the detector into other JVMs on the same system. You specify the JVM by its PID. The following example attaches the file leak detector to the pid 1500. Options can be specified in the 2nd argument in the same format you do to the agent.
$ java -jar path/to/file-leak-detector.jar 1500 threshold=200,strong