test/java/util/logging/LoggingDeadlock2.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) 2006, 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  */


  86             Thread exiter = new Thread() {
  87                 public void run() {
  88                     try {
  89                         startingGate.await();
  90                         for (int i = 0; i < iters1; i++)
  91                             counter.getAndIncrement();
  92                         System.exit(99);
  93                     } catch (Throwable t) {
  94                         t.printStackTrace();
  95                         System.exit(86);
  96                     }
  97                 }};
  98             exiter.start();
  99 
 100             startingGate.await();
 101             for (int i = 0; i < iters2; i++)
 102                 counter.getAndIncrement();
 103             // This may or may not result in a first call to
 104             // Runtime.addShutdownHook after shutdown has already
 105             // commenced.
 106             LogManager log = LogManager.getLogManager();
 107 
 108             if (dojoin) {
 109                 exiter.join();
 110                 if (thrown[0] != null)
 111                     throw new Error(thrown[0]);
 112                 check(counter.get() == JITTER);
 113             }
 114         }
 115     }
 116 
 117     //----------------------------------------------------------------
 118     // The rest of this test is copied from ProcessBuilder/Basic.java
 119     //----------------------------------------------------------------
 120     private static final String javaExe =
 121         System.getProperty("java.home") +
 122         File.separator + "bin" + File.separator + "java";
 123 
 124     private static final String classpath =
 125         System.getProperty("java.class.path");
 126 


 131 
 132     private static class ProcessResults {
 133         private final String out;
 134         private final String err;
 135         private final int exitValue;
 136         private final Throwable throwable;
 137 
 138         public ProcessResults(String out,
 139                               String err,
 140                               int exitValue,
 141                               Throwable throwable) {
 142             this.out = out;
 143             this.err = err;
 144             this.exitValue = exitValue;
 145             this.throwable = throwable;
 146         }
 147 
 148         public String out()          { return out; }
 149         public String err()          { return err; }
 150         public int exitValue()       { return exitValue; }
 151         public Throwable throwable() { return throwable; }
 152 
 153         public String toString() {
 154             StringBuilder sb = new StringBuilder();
 155             sb.append("<STDOUT>\n" + out() + "</STDOUT>\n")
 156                 .append("<STDERR>\n" + err() + "</STDERR>\n")
 157                 .append("exitValue = " + exitValue + "\n");
 158             if (throwable != null)
 159                 sb.append(throwable.getStackTrace());
 160             return sb.toString();
 161         }
 162     }
 163 
 164     private static class StreamAccumulator extends Thread {
 165         private final InputStream is;
 166         private final StringBuilder sb = new StringBuilder();
 167         private Throwable throwable = null;
 168 
 169         public String result () throws Throwable {
 170             if (throwable != null)
 171                 throw throwable;


   1 /*
   2  * Copyright (c) 2006, 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  */


  86             Thread exiter = new Thread() {
  87                 public void run() {
  88                     try {
  89                         startingGate.await();
  90                         for (int i = 0; i < iters1; i++)
  91                             counter.getAndIncrement();
  92                         System.exit(99);
  93                     } catch (Throwable t) {
  94                         t.printStackTrace();
  95                         System.exit(86);
  96                     }
  97                 }};
  98             exiter.start();
  99 
 100             startingGate.await();
 101             for (int i = 0; i < iters2; i++)
 102                 counter.getAndIncrement();
 103             // This may or may not result in a first call to
 104             // Runtime.addShutdownHook after shutdown has already
 105             // commenced.
 106             LogManager.getLogManager();
 107 
 108             if (dojoin) {
 109                 exiter.join();
 110                 if (thrown[0] != null)
 111                     throw new Error(thrown[0]);
 112                 check(counter.get() == JITTER);
 113             }
 114         }
 115     }
 116 
 117     //----------------------------------------------------------------
 118     // The rest of this test is copied from ProcessBuilder/Basic.java
 119     //----------------------------------------------------------------
 120     private static final String javaExe =
 121         System.getProperty("java.home") +
 122         File.separator + "bin" + File.separator + "java";
 123 
 124     private static final String classpath =
 125         System.getProperty("java.class.path");
 126 


 131 
 132     private static class ProcessResults {
 133         private final String out;
 134         private final String err;
 135         private final int exitValue;
 136         private final Throwable throwable;
 137 
 138         public ProcessResults(String out,
 139                               String err,
 140                               int exitValue,
 141                               Throwable throwable) {
 142             this.out = out;
 143             this.err = err;
 144             this.exitValue = exitValue;
 145             this.throwable = throwable;
 146         }
 147 
 148         public String out()          { return out; }
 149         public String err()          { return err; }
 150         public int exitValue()       { return exitValue; }

 151 
 152         public String toString() {
 153             StringBuilder sb = new StringBuilder();
 154             sb.append("<STDOUT>\n" + out() + "</STDOUT>\n")
 155                 .append("<STDERR>\n" + err() + "</STDERR>\n")
 156                 .append("exitValue = " + exitValue + "\n");
 157             if (throwable != null)
 158                 sb.append(throwable.getStackTrace());
 159             return sb.toString();
 160         }
 161     }
 162 
 163     private static class StreamAccumulator extends Thread {
 164         private final InputStream is;
 165         private final StringBuilder sb = new StringBuilder();
 166         private Throwable throwable = null;
 167 
 168         public String result () throws Throwable {
 169             if (throwable != null)
 170                 throw throwable;