Reputation: 11
my issue is to monitor open file handles in java and being independent from the type of OS (Linux, Windows, etc)
My Application is a web based server application running with tomcat and Java8.
For a possible solution only the Java-Language itself and both, Guava and Apache Commons, are to be considered as my company does not allow the use of any other third party libraries.
Any suggestions on how to do that? I already thought of inheriting an InputStream
and injecting some stuff into its open()
and close()
methods but this is not really whats I consider a "good" solution...
I'd be very thankful for your help!
Upvotes: 1
Views: 2511
Reputation: 25481
https://github.com/jenkinsci/lib-file-leak-detector can do this provided you have enough control of the environment to pass -javaagent
. It would not be appropriate to run in production.
Upvotes: 1
Reputation: 2786
The solution you don't really like seems to be the best one, you can simply emit a message, for example through an EventBus (you have it in Guava), whenever you open or close a file. Your ManagedFileInputStream
has just to call enventBus.post(someFilePointer)
and super.open()
or super.close()
.
But there are many other file that could be opened by your application (jar files, web resources like css , images, scripts, temporary file created by tomcat , temporary files created by the JVM).
I think that there is no sensible way to monitor all file opened by a java application from within the java Application, maybe that's something for the OS to manage.
Upvotes: 0