This project has been handed down to me, so I do not know much about it. There is a method where log (java.util.logging.Logger) is used and it creates two log files:
First file: fileName.log
Second file: fileName.log.lck
In Linux when I do lsof
, I see these two files as open. How do I close these two files?
The reason why I want to close these files is this method is run multiple times a day and after couple of weeks the number of open files reaches a limit (around 1000), at which point our system stops working. When we restart our process ("Job Controller" which does the logging) the number of log files open goes to 0 and it works again.
This is what's been done to do logging
private static Logger log = Logger.getLogger(MyClass.class.getPackage().getName());
try{
log.logp(Level.SEVERE, "com.MyClass", "run", "It failed");
}
This is what I tried to do to close the files in the finally block but it didn't work
finally{
Handler[] handler = log.getHandlers();
for(Handler h: handler){
h.close();
}
}
close()
). In case you actually do need a bunch of files open, it's possible to increase the limit. – Lineationfinally
block? That appears to be the correct way to do it. Are you getting an error or is it just not closing the files? – Lineation