jdk/test/java/util/logging/ClassLoaderLeakTest.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 7803 56bc97d69d93
child 14683 38921a46c62d
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2384
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 7803
diff changeset
     2
 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
2384
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
     4
 *
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
     8
 *
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    13
 * accompanied this code).
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    14
 *
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2384
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2384
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2384
diff changeset
    21
 * questions.
2384
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    22
 */
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    23
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    24
/**
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    25
 * @test
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    26
 * @bug     6799583
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    27
 *
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    28
 * @summary Test verifes that LogManager shutdown hook does not cause
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    29
 *          an application classloader leaks.
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    30
 *
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    31
 * @run     main/othervm ClassLoaderLeakTest
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    32
 */
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    33
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    34
import java.io.File;
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    35
import java.lang.ref.WeakReference;
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    36
import java.lang.reflect.Constructor;
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    37
import java.lang.reflect.Method;
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    38
import java.net.MalformedURLException;
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    39
import java.net.URL;
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    40
import java.net.URLClassLoader;
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    41
import java.util.concurrent.CountDownLatch;
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    42
import java.util.logging.Logger;
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    43
import java.util.logging.Logger;
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    44
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    45
public class ClassLoaderLeakTest {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    46
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    47
    private static CountDownLatch doneSignal;
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    48
    private static CountDownLatch launchSignal;
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    49
    private static ThreadGroup appsThreadGroup;
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    50
    private static Throwable launchFailure = null;
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    51
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    52
    public static void main(String[] args) {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    53
        appsThreadGroup = new ThreadGroup("MyAppsThreadGroup");
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    54
        doneSignal = new CountDownLatch(1);
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    55
        launchSignal = new CountDownLatch(1);
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    56
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    57
        Runnable launcher = new Runnable() {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    58
            public void run() {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    59
                try {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    60
                    ClassLoader cl =
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    61
                        Thread.currentThread().getContextClassLoader();
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    62
                    Class appMain = cl.loadClass("AppTest");
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    63
                    Method launch =
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    64
                        appMain.getDeclaredMethod("launch", doneSignal.getClass());
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    65
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    66
                    Constructor c = appMain.getConstructor();
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    67
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    68
                    Object o = c.newInstance();
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    69
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    70
                    launch.invoke(o, doneSignal);
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    71
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    72
                } catch (Throwable e) {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    73
                    launchFailure = e;
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    74
                } finally {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    75
                    launchSignal.countDown();
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    76
                }
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    77
            }
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    78
        };
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    79
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    80
        /* prepare test  class loader */
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    81
        URL pwd = null;
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    82
        try {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    83
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    84
            pwd = new File(System.getProperty("test.classes",".")).toURL();
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    85
        } catch (MalformedURLException e) {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    86
            throw new RuntimeException("Test failed.", e);
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    87
        }
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    88
        URL[] urls = new URL[] { pwd };
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    89
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    90
         MyClassLoader appClassLoader = new MyClassLoader(urls, "test0");
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    91
         WeakReference<MyClassLoader> ref =
7803
56bc97d69d93 6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents: 5506
diff changeset
    92
                 new WeakReference<>(appClassLoader);
2384
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    93
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    94
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    95
         Thread appThread = new Thread(appsThreadGroup, launcher, "AppThread-0");
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    96
         appThread.setContextClassLoader(appClassLoader);
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    97
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    98
         appThread.start();
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
    99
         appClassLoader = null;
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   100
         launcher = null;
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   101
         appThread = null;
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   102
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   103
         /* wait for laucnh completion */
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   104
         try {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   105
             launchSignal.await();
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   106
         } catch (InterruptedException e) {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   107
         }
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   108
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   109
         /* check if launch failed */
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   110
         if (launchFailure != null) {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   111
             throw new RuntimeException("Test failed.", launchFailure);
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   112
         }
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   113
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   114
         /* wait for test app excution completion */
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   115
         try {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   116
             doneSignal.await();
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   117
         } catch (InterruptedException e) {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   118
         }
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   119
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   120
         /* give a chence to GC */
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   121
         waitAndGC(5);
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   122
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   123
         if (ref.get() != null) {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   124
             throw new RuntimeException("Test failed: classloader is still alive");
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   125
         }
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   126
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   127
         System.out.println("Test passed.");
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   128
    }
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   129
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   130
    private static class MyClassLoader extends URLClassLoader {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   131
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   132
        private static boolean verbose =
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   133
            Boolean.getBoolean("verboseClassLoading");
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   134
        private String uniqClassName;
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   135
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   136
        public MyClassLoader(URL[] urls, String uniq) {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   137
            super(urls);
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   138
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   139
            uniqClassName = uniq;
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   140
        }
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   141
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   142
        public Class loadClass(String name) throws ClassNotFoundException {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   143
            if (verbose) {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   144
                System.out.printf("%s: load class %s\n", uniqClassName, name);
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   145
            }
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   146
            if (uniqClassName.equals(name)) {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   147
                return Object.class;
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   148
            }
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   149
            return super.loadClass(name);
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   150
        }
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   151
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   152
        public String toString() {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   153
            return "MyClassLoader(" + uniqClassName + ")";
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   154
        }
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   155
    }
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   156
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   157
    private static void waitAndGC(int sec) {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   158
        int cnt = sec;
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   159
        System.out.print("Wait ");
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   160
        while (cnt-- > 0) {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   161
            try {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   162
                Thread.sleep(1000);
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   163
            } catch (InterruptedException e) {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   164
            }
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   165
            // do GC every 3 seconds
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   166
            if (cnt % 3 == 2) {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   167
                System.gc();
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   168
                System.out.print("+");
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   169
            } else {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   170
                System.out.print(".");
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   171
            }
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   172
            //checkErrors();
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   173
        }
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   174
        System.out.println("");
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   175
    }
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   176
}
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   177
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   178
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   179
class AppTest {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   180
    public AppTest() {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   181
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   182
    }
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   183
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   184
    public void launch(CountDownLatch done) {
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   185
        Logger log = Logger.getLogger("app_test_logger");
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   186
        log.fine("Test app is launched");
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   187
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   188
        done.countDown();
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   189
    }
b3ba5fb77f89 6799583: LogManager shutdown hook may cause a memory leak.
bae
parents:
diff changeset
   190
}