title: Close log files
body: <p>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:</p>
  
  <p>First file: fileName.log</p>
  
  <p>Second file: fileName.log.lck</p>
  
  <p>In Linux when I do <code>lsof</code>, I see these two files as open. How do I close these two files? </p>
  
  <p>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. </p>
  
  <p>This is what's been done to do logging</p>
  
  <pre><code>private static Logger log = Logger.getLogger(MyClass.class.getPackage().getName());
  try{
      log.logp(Level.SEVERE, "com.MyClass", "run", "It failed");
  }
  </code></pre>
  
  <p>This is what I tried to do to close the files in the finally block but it didn't work</p>
  
  <pre><code>finally{
      Handler[] handler =   log.getHandlers();
      for(Handler h: handler){
          h.close();
      }
  }
  </code></pre>