test/java/util/logging/LoggingDeadlock3.java

Print this page
rev 6099 : 8003380: Compiler warnings in logging test code
Summary: Use generics, suppress warnings where appropriate, remove unused imports, etc.
Reviewed-by: lancea, chegar
   1 /*
   2  * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  44     String tstSrc = System.getProperty("test.src");
  45     File   fname  = new File(tstSrc, "LoggingDeadlock3.props");
  46     String prop   = fname.getCanonicalPath();
  47     System.setProperty("java.util.logging.config.file", prop);
  48     logMgr.readConfiguration();
  49 
  50     Thread t1 = new Thread(new AddLogger());
  51     Thread t2 = new Thread(new GetLogger());
  52     t1.start(); t2.start();
  53     t1.join();  t2.join();
  54     out.println("\n" + MSG_PASSED);
  55   }
  56 
  57   public static class MyLogger extends Logger {
  58     protected MyLogger(String name) { super(name, null); }
  59   }
  60 
  61   public static class GetLogger implements Runnable {
  62     public void run() {
  63       for (int cnt = 0; cnt < ITER_CNT * 8; cnt++) {
  64         Logger logger = Logger.getLogger("com.sun.Hello"+cnt/10);
  65         if (cnt % 1000  == 0) out.print("1");
  66         if (cnt % 10000 == 0) out.println();
  67       }
  68     }
  69   }
  70 
  71   public static class AddLogger implements Runnable {
  72     public void run() {
  73       for (int cnt = 0; cnt < ITER_CNT; cnt++) {
  74         Logger addLogger = new MyLogger("com.sun.Hello"+cnt);
  75         logMgr.addLogger(addLogger);
  76         if (cnt % 100  == 0) out.print("2");
  77         if (cnt % 1000 == 0) out.println();
  78       }
  79     }
  80   }
  81 }
   1 /*
   2  * Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  44     String tstSrc = System.getProperty("test.src");
  45     File   fname  = new File(tstSrc, "LoggingDeadlock3.props");
  46     String prop   = fname.getCanonicalPath();
  47     System.setProperty("java.util.logging.config.file", prop);
  48     logMgr.readConfiguration();
  49 
  50     Thread t1 = new Thread(new AddLogger());
  51     Thread t2 = new Thread(new GetLogger());
  52     t1.start(); t2.start();
  53     t1.join();  t2.join();
  54     out.println("\n" + MSG_PASSED);
  55   }
  56 
  57   public static class MyLogger extends Logger {
  58     protected MyLogger(String name) { super(name, null); }
  59   }
  60 
  61   public static class GetLogger implements Runnable {
  62     public void run() {
  63       for (int cnt = 0; cnt < ITER_CNT * 8; cnt++) {
  64         Logger.getLogger("com.sun.Hello"+cnt/10);
  65         if (cnt % 1000  == 0) out.print("1");
  66         if (cnt % 10000 == 0) out.println();
  67       }
  68     }
  69   }
  70 
  71   public static class AddLogger implements Runnable {
  72     public void run() {
  73       for (int cnt = 0; cnt < ITER_CNT; cnt++) {
  74         Logger addLogger = new MyLogger("com.sun.Hello"+cnt);
  75         logMgr.addLogger(addLogger);
  76         if (cnt % 100  == 0) out.print("2");
  77         if (cnt % 1000 == 0) out.println();
  78       }
  79     }
  80   }
  81 }