Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8049850

Java Logging, lck files not deleted in Multi JVM environment

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 6u26
    • core-libs

      A DESCRIPTION OF THE REQUEST :
      We have an application which runs on clustered servers and all logs generated from the app are logged in one shared space. We are consistently seeing that most of the times when both JVMs try to write to same file name a xxx.log.yy file is being created (one per JVM) . Also corresponding LCK are created as well and they are not deleted even after the file handler is closed.

      JUSTIFICATION :
      this bug is causing unncessary clutter of files on our servers.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Create one log file xxxx.log (not xxxx.log.yy per JVM). Also LCk files should be deleted as soon as file handler is closed on all JVMs
      ACTUAL -
      LCK files are left open and mutliple log files are being created

      ---------- BEGIN SOURCE ----------
      //Sample code : Run TestConcurrentLogging

      public class LoggerClass {

      private static Logger logger = Logger.getAnonymousLogger();
      private Map <String, Handler> m = new HashMap<String, Handler>();
      static
      {
      logger.setLevel(Level.ALL);
      }
      public synchronized void log(String message) throws SecurityException, IOException
      {
      configFileHandler(message);
      logger.fine(message);
      }
      private void configFileHandler(String message) throws SecurityException, IOException
      {
      String s = message.substring(0,1);

      getFileHandler(s);
      }

      public synchronized void errorLog(String message, Throwable t) throws SecurityException, IOException
      {
      configFileHandler(message);
      StringWriter sw = new StringWriter();
      PrintWriter p = new PrintWriter(sw);

      t.printStackTrace(p);
      p.flush();
      logger.log(Level.SEVERE, message, t);
      //logger.severe(message + sw.getBuffer().toString());
      }

      private void getFileHandler(String s) throws SecurityException, IOException
      {

      Handler h = m.get(s);
      if(h == null )
      {
      h = new FileHandler(s + ".log");
      logger.setUseParentHandlers(false);
      h.setFormatter(new java.util.logging.SimpleFormatter());
      m.put(s,h);
      }
      for(Handler hf:logger.getHandlers()){logger.removeHandler(hf);}
      logger.addHandler(m.get(s));
      }

      public synchronized void close(String ss)
      {
      String s = ss.substring(0,1);
      Handler h = m.get(s);
      if (h != null)
      h.close();
      System.out.println("Closing " + s + h);
      }
      }

      class TestConcurrentLogging {

      /**
      * @param args
      * @throws IOException
      * @throws SecurityException
      * @throws InterruptedException
      */
      public static void main(String[] args) throws SecurityException, IOException, InterruptedException {
      LoggerClass l = new LoggerClass();
      T t = new T("1", l);
      T t2 = new T ("2", l);
      T t3 = new T ("3", l);
      t.start();
      t2.start();
      t3.start();
      l.log("AB");
      t.join();
      t2.join();
      t3.join();
      l.errorLog("AB",new Exception("My Upper",new Exception("My Inner")));
      l.close("AB");
      }
      static class T extends Thread
      {
      String ss;
      LoggerClass ll;
      T (String s, LoggerClass l)
      {
      this.ss = s;
      this.ll = l;
      }
      @Override
      public void run() {
      for (int i = 0; i < 10000; i ++)
      {try {
      ll.log(ss + " My message");
      } catch (SecurityException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      }
      }
      this.ll.close(ss);
      }
      }
      }


      ---------- END SOURCE ----------

            dfuchs Daniel Fuchs
            coffeys Sean Coffey
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Imported: