author | dfuchs |
Sun, 22 Dec 2013 11:20:07 +0100 | |
changeset 22086 | 866b0a7d0127 |
parent 22073 | 3cac022a1634 |
child 25985 | aa1e188ea8bf |
permissions | -rw-r--r-- |
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
1 |
/* |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
4 |
* |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
8 |
* |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
13 |
* accompanied this code). |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
14 |
* |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
18 |
* |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
21 |
* questions. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
22 |
*/ |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
23 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
24 |
import java.lang.management.ManagementFactory; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
25 |
import java.lang.management.ThreadInfo; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
26 |
import java.security.Permission; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
27 |
import java.security.Policy; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
28 |
import java.security.ProtectionDomain; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
29 |
import java.util.ArrayList; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
30 |
import java.util.List; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
31 |
import java.util.ListResourceBundle; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
32 |
import java.util.Objects; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
33 |
import java.util.ResourceBundle; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
34 |
import java.util.concurrent.Callable; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
35 |
import java.util.concurrent.ExecutorService; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
36 |
import java.util.concurrent.Executors; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
37 |
import java.util.concurrent.FutureTask; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
38 |
import java.util.concurrent.atomic.AtomicLong; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
39 |
import java.util.logging.Handler; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
40 |
import java.util.logging.Level; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
41 |
import java.util.logging.LogRecord; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
42 |
import java.util.logging.Logger; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
43 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
44 |
/** |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
45 |
* @test |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
46 |
* @bug 8029281 8028763 |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
47 |
* @summary Attempts to detect synchronization issues with getResourceBundle() |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
48 |
* and getResourceBundleName(). It might also detect issues in the way |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
49 |
* that the logger tree is cleaned up after a logger has been garbage |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
50 |
* collected. This test helped find the root cause of 8029092, so if |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
51 |
* this test fails one might also expect failures in |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
52 |
* java/util/logging/Logger/logrb/TestLogrbResourceBundle.java and |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
53 |
* java/util/logging/Logger/setResourceBundle/TestSetResourceBundle.java. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
54 |
* Note that this is a best effort test. Running it in a loop to |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
55 |
* reproduce intermittent issues can be a good idea. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
56 |
* @run main/othervm TestLoggerBundleSync |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
57 |
* @author danielfuchs |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
58 |
*/ |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
59 |
public class TestLoggerBundleSync { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
60 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
61 |
static volatile Exception thrown = null; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
62 |
static volatile boolean goOn = true; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
63 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
64 |
static final int READERS = 3; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
65 |
static final long TIME = 4 * 1000; // 4 sec. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
66 |
static final long STEP = 1 * 1000; // message every 1 sec. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
67 |
static final int LCOUNT = 50; // change bundle 50 times... |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
68 |
static final AtomicLong setRBcount = new AtomicLong(0); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
69 |
static final AtomicLong setRBNameCount = new AtomicLong(0); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
70 |
static final AtomicLong getRBcount = new AtomicLong(0); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
71 |
static final AtomicLong checkCount = new AtomicLong(0); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
72 |
static final AtomicLong nextLong = new AtomicLong(0); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
73 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
74 |
public static class MyBundle extends ListResourceBundle { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
75 |
@Override |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
76 |
protected Object[][] getContents() { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
77 |
return new Object[][] { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
78 |
{"dummy", "foo"} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
79 |
}; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
80 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
81 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
82 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
83 |
public static final class MyBundle1 extends MyBundle { }; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
84 |
public static final class MyBundle2 extends MyBundle { }; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
85 |
public static final class MyBundle3 extends MyBundle { }; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
86 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
87 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
88 |
public static final class LoggerRB { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
89 |
public final String resourceBundleName; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
90 |
public final ResourceBundle userBundle; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
91 |
public LoggerRB(String name, ResourceBundle bundle) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
92 |
resourceBundleName = name; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
93 |
userBundle = bundle; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
94 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
95 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
96 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
97 |
static final List<Class<? extends ResourceBundle>> classes = new ArrayList<>(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
98 |
static { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
99 |
classes.add(MyBundle1.class); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
100 |
classes.add(MyBundle2.class); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
101 |
classes.add(MyBundle3.class); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
102 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
103 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
104 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
105 |
/** |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
106 |
* This test will run both with and without a security manager. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
107 |
* |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
108 |
* The test starts a number of threads that will attempt to concurrently |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
109 |
* set resource bundles on Logger, and verifies the consistency of the |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
110 |
* obtained results. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
111 |
* |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
112 |
* This is a best effort test. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
113 |
* |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
114 |
* @param args the command line arguments |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
115 |
*/ |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
116 |
public static void main(String[] args) throws Exception { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
117 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
118 |
try { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
119 |
// test without security |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
120 |
System.out.println("No security"); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
121 |
test(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
122 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
123 |
// test with security |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
124 |
System.out.println("\nWith security"); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
125 |
Policy.setPolicy(new Policy() { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
126 |
@Override |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
127 |
public boolean implies(ProtectionDomain domain, Permission permission) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
128 |
if (super.implies(domain, permission)) return true; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
129 |
// System.out.println("Granting " + permission); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
130 |
return true; // all permissions |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
131 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
132 |
}); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
133 |
System.setSecurityManager(new SecurityManager()); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
134 |
test(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
135 |
} finally { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
136 |
SetRB.executor.shutdownNow(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
137 |
SetRBName.executor.shutdownNow(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
138 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
139 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
140 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
141 |
/** |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
142 |
* Starts all threads, wait 15secs, then stops all threads. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
143 |
* @throws Exception if a deadlock was detected or an error occurred. |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
144 |
*/ |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
145 |
public static void test() throws Exception { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
146 |
goOn = true; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
147 |
thrown = null; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
148 |
long sGetRBCount = getRBcount.get(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
149 |
long sSetRBCount = setRBcount.get(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
150 |
long sSetRBNameCount = setRBNameCount.get(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
151 |
long sCheckCount = checkCount.get(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
152 |
long sNextLong = nextLong.get(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
153 |
List<Thread> threads = new ArrayList<>(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
154 |
for (Class<? extends ResourceBundle> type : classes) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
155 |
threads.add(new SetRB(type)); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
156 |
threads.add(new SetRBName(type)); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
157 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
158 |
for (int i =0 ; i < READERS ; i++) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
159 |
threads.add(new GetRB()); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
160 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
161 |
threads.add(new DeadlockDetector()); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
162 |
threads.add(0, new Stopper(TIME)); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
163 |
for (Thread t : threads) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
164 |
t.start(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
165 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
166 |
for (Thread t : threads) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
167 |
try { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
168 |
t.join(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
169 |
} catch (Exception x) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
170 |
fail(x); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
171 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
172 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
173 |
if (thrown != null) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
174 |
throw thrown; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
175 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
176 |
System.out.println("Passed: " + (nextLong.longValue() - sNextLong) |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
177 |
+ " unique loggers created"); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
178 |
System.out.println("\t " +(getRBcount.get() - sGetRBCount) |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
179 |
+ " loggers tested by " + READERS + " Thread(s),"); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
180 |
System.out.println("\t " + (setRBcount.get() - sSetRBCount) |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
181 |
+ " resource bundles set by " + classes.size() + " Thread(s),"); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
182 |
System.out.println("\t " + (setRBNameCount.get() - sSetRBNameCount) |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
183 |
+ " resource bundle names set by " + classes.size() + " Thread(s),"); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
184 |
System.out.println("\t ThreadMXBean.findDeadlockedThreads called " |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
185 |
+ (checkCount.get() -sCheckCount) + " times by 1 Thread."); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
186 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
187 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
188 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
189 |
final static class GetRB extends Thread { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
190 |
final static class MyHandler extends Handler { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
191 |
volatile ResourceBundle rb; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
192 |
volatile String rbName; |
22073
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
193 |
volatile int count = 0; |
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
194 |
@Override |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
195 |
public synchronized void publish(LogRecord record) { |
22073
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
196 |
count++; |
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
197 |
rb = record.getResourceBundle(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
198 |
rbName = record.getResourceBundleName(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
199 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
200 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
201 |
@Override |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
202 |
public void flush() { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
203 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
204 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
205 |
@Override |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
206 |
public void close() throws SecurityException { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
207 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
208 |
}; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
209 |
final MyHandler handler = new MyHandler(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
210 |
@Override |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
211 |
public void run() { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
212 |
try { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
213 |
handler.setLevel(Level.FINEST); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
214 |
while (goOn) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
215 |
Logger l; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
216 |
Logger foo = Logger.getLogger("foo"); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
217 |
Logger bar = Logger.getLogger("foo.bar"); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
218 |
for (long i=0; i < nextLong.longValue() + 100 ; i++) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
219 |
if (!goOn) break; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
220 |
l = Logger.getLogger("foo.bar.l"+i); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
221 |
final ResourceBundle b = l.getResourceBundle(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
222 |
final String name = l.getResourceBundleName(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
223 |
if (b != null) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
224 |
if (!name.equals(b.getBaseBundleName())) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
225 |
throw new RuntimeException("Unexpected bundle name: " |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
226 |
+b.getBaseBundleName()); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
227 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
228 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
229 |
Logger ll = Logger.getLogger(l.getName()+".bie.bye"); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
230 |
ResourceBundle hrb; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
231 |
String hrbName; |
22073
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
232 |
if (handler.getLevel() != Level.FINEST) { |
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
233 |
throw new RuntimeException("Handler level is not finest: " |
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
234 |
+ handler.getLevel()); |
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
235 |
} |
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
236 |
final int countBefore = handler.count; |
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
237 |
ll.setLevel(Level.FINEST); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
238 |
ll.addHandler(handler); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
239 |
ll.fine("dummy"); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
240 |
ll.removeHandler(handler); |
22073
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
241 |
final int countAfter = handler.count; |
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
242 |
if (countBefore == countAfter) { |
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
243 |
throw new RuntimeException("Handler not called for " |
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
244 |
+ ll.getName() + "("+ countAfter +")"); |
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
245 |
} |
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
246 |
hrb = handler.rb; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
247 |
hrbName = handler.rbName; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
248 |
if (name != null) { |
22073
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
249 |
// if name is not null, then it implies that it |
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
250 |
// won't change, since setResourceBundle() cannot |
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
251 |
// replace a non null name. |
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
252 |
// Since we never set the resource bundle on 'll', |
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
253 |
// then ll must inherit its resource bundle [name] |
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
254 |
// from l - and therefor we should find it in |
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
255 |
// handler.rb/handler.rbName |
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
256 |
if (!name.equals(hrbName)) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
257 |
throw new RuntimeException("Unexpected bundle name: " |
22073
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
258 |
+hrbName); |
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
259 |
} |
22073
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
260 |
// here we know that hrbName is not null so hrb |
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
261 |
// should not be null either. |
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
262 |
if (!name.equals(hrb.getBaseBundleName())) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
263 |
throw new RuntimeException("Unexpected bundle name: " |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
264 |
+hrb.getBaseBundleName()); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
265 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
266 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
267 |
|
22073
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
268 |
// Make sure to refer to 'l' explicitly in order to |
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
269 |
// prevent eager garbage collecting before the end of |
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
270 |
// the test (JDK-8030192) |
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
271 |
if (!ll.getName().startsWith(l.getName())) { |
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
272 |
throw new RuntimeException("Logger " + ll.getName() |
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
273 |
+ "does not start with expected prefix " |
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
274 |
+ l.getName()); |
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
275 |
} |
3cac022a1634
8030192: TESTFAIL: java/util/logging/TestLoggerBundleSync.java failed with NPE
dfuchs
parents:
21960
diff
changeset
|
276 |
|
21960
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
277 |
getRBcount.incrementAndGet(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
278 |
if (!goOn) break; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
279 |
Thread.sleep(1); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
280 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
281 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
282 |
} catch (Exception x) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
283 |
fail(x); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
284 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
285 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
286 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
287 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
288 |
final static class SetRB extends Thread { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
289 |
final Class<? extends ResourceBundle> type; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
290 |
final static ExecutorService executor = Executors.newSingleThreadExecutor(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
291 |
final static class CheckRBTask implements Callable<Exception> { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
292 |
final Logger logger; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
293 |
volatile String rbName; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
294 |
volatile ResourceBundle rb; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
295 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
296 |
public CheckRBTask(Logger logger) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
297 |
this.logger = logger; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
298 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
299 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
300 |
@Override |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
301 |
public Exception call() throws Exception { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
302 |
try { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
303 |
final String name = logger.getResourceBundleName(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
304 |
if (!Objects.equals(name, rbName)) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
305 |
throw new RuntimeException("Unexpected rbname for " |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
306 |
+ logger.getName() + ": " + name); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
307 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
308 |
final ResourceBundle b = logger.getResourceBundle(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
309 |
if (b != rb) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
310 |
throw new RuntimeException("Unexpected rb for " |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
311 |
+ logger.getName() + ": " + b); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
312 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
313 |
} catch(Exception x) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
314 |
return x; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
315 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
316 |
return null; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
317 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
318 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
319 |
public void check() throws Exception { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
320 |
final FutureTask<Exception> futureTask = new FutureTask<>(this); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
321 |
executor.submit(futureTask); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
322 |
Exception x = futureTask.get(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
323 |
if ( x != null) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
324 |
throw new RuntimeException("Check failed: "+x,x); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
325 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
326 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
327 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
328 |
SetRB(Class<? extends ResourceBundle> type) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
329 |
super("SetRB["+type.getSimpleName()+"]"); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
330 |
this.type = type; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
331 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
332 |
@Override |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
333 |
public void run() { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
334 |
try { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
335 |
while (goOn) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
336 |
Logger l; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
337 |
Logger foo = Logger.getLogger("foo"); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
338 |
Logger bar = Logger.getLogger("foo.bar"); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
339 |
l = Logger.getLogger("foo.bar.l"+nextLong.incrementAndGet()); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
340 |
final CheckRBTask checkTask = new CheckRBTask(l); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
341 |
checkTask.check(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
342 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
343 |
for (int i=0; i < LCOUNT ; i++) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
344 |
if (!goOn) break; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
345 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
346 |
ResourceBundle b = ResourceBundle.getBundle(type.getName()); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
347 |
try { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
348 |
l.setResourceBundle(b); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
349 |
checkTask.rb = b; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
350 |
checkTask.rbName = type.getName(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
351 |
checkTask.check(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
352 |
if (!goOn) break; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
353 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
354 |
String name = l.getResourceBundleName(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
355 |
ResourceBundle bb = l.getResourceBundle(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
356 |
if (!type.getName().equals(name)) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
357 |
throw new RuntimeException(this.getName() |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
358 |
+ ": Unexpected name: "+name); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
359 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
360 |
if (!b.getBaseBundleName().equals(name)) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
361 |
throw new RuntimeException(this.getName() |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
362 |
+ ": Unexpected base name: " + |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
363 |
b.getBaseBundleName()); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
364 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
365 |
if (b != bb) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
366 |
throw new RuntimeException(this.getName() |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
367 |
+ ": Unexpected bundle: "+bb); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
368 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
369 |
setRBcount.incrementAndGet(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
370 |
} catch (IllegalArgumentException x) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
371 |
final String name = l.getResourceBundleName(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
372 |
if (!name.startsWith(MyBundle.class.getName())) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
373 |
throw new RuntimeException(this.getName() |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
374 |
+ ": Unexpected name: "+name, x); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
375 |
} else if (type.getName().equals(name)) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
376 |
throw new RuntimeException(this.getName() |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
377 |
+ ": Unexpected exception for "+name, x); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
378 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
379 |
throw x; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
380 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
381 |
l.fine("I'm fine"); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
382 |
if (!goOn) break; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
383 |
Thread.sleep(1); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
384 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
385 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
386 |
} catch (Exception x) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
387 |
fail(x); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
388 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
389 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
390 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
391 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
392 |
final static class SetRBName extends Thread { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
393 |
int nexti = 0; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
394 |
final Class<? extends ResourceBundle> type; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
395 |
final static ExecutorService executor = Executors.newSingleThreadExecutor(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
396 |
final static class CheckRBNameTask implements Callable<Exception> { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
397 |
final Logger logger; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
398 |
volatile String rbName; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
399 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
400 |
public CheckRBNameTask(Logger logger) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
401 |
this.logger = logger; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
402 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
403 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
404 |
@Override |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
405 |
public Exception call() throws Exception { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
406 |
try { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
407 |
final String name = logger.getResourceBundleName(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
408 |
if (!Objects.equals(name, rbName)) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
409 |
throw new RuntimeException("Unexpected rbname for " |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
410 |
+ logger.getName() + ": " + name); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
411 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
412 |
final ResourceBundle b = logger.getResourceBundle(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
413 |
if (!Objects.equals(b == null ? null : b.getBaseBundleName(), rbName)) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
414 |
throw new RuntimeException("Unexpected base name for " |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
415 |
+ logger.getName() + ": " + b.getBaseBundleName()); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
416 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
417 |
} catch(Exception x) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
418 |
return x; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
419 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
420 |
return null; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
421 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
422 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
423 |
public void check() throws Exception { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
424 |
final FutureTask<Exception> futureTask = new FutureTask<>(this); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
425 |
executor.submit(futureTask); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
426 |
Exception x = futureTask.get(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
427 |
if ( x != null) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
428 |
throw new RuntimeException("Check failed: "+x,x); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
429 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
430 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
431 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
432 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
433 |
SetRBName(Class<? extends ResourceBundle> type) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
434 |
super("SetRB["+type.getSimpleName()+"]"); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
435 |
this.type = type; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
436 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
437 |
@Override |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
438 |
public void run() { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
439 |
try { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
440 |
while (goOn) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
441 |
Logger foo = Logger.getLogger("foo"); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
442 |
Logger bar = Logger.getLogger("foo.bar"); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
443 |
Logger l = Logger.getLogger("foo.bar.l"+nextLong.incrementAndGet()); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
444 |
final CheckRBNameTask checkTask = new CheckRBNameTask(l); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
445 |
checkTask.check(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
446 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
447 |
for (int i=0; i < LCOUNT ; i++) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
448 |
if (!goOn) break; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
449 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
450 |
try { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
451 |
Logger l2 = Logger.getLogger(l.getName(), type.getName()); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
452 |
if (l2 != l) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
453 |
System.err.println("**** ERROR WITH "+l.getName()); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
454 |
throw new RuntimeException("l2 != l [" |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
455 |
+ l2 + "(" + l2.getName() + ") != " |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
456 |
+ l + "(" + l.getName() + ")]"); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
457 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
458 |
checkTask.rbName = type.getName(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
459 |
checkTask.check(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
460 |
if (!goOn) break; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
461 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
462 |
String name = l.getResourceBundleName(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
463 |
ResourceBundle bb = l.getResourceBundle(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
464 |
if (!type.getName().equals(name)) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
465 |
throw new RuntimeException(this.getName() |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
466 |
+ ": Unexpected name: "+name); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
467 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
468 |
if (!bb.getBaseBundleName().equals(name)) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
469 |
throw new RuntimeException(this.getName() |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
470 |
+ ": Unexpected base name: " |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
471 |
+ bb.getBaseBundleName()); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
472 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
473 |
setRBNameCount.incrementAndGet(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
474 |
} catch (IllegalArgumentException x) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
475 |
final String name = l.getResourceBundleName(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
476 |
if (!name.startsWith(MyBundle.class.getName())) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
477 |
throw new RuntimeException(this.getName() |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
478 |
+ ": Unexpected name: "+name, x); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
479 |
} else if (type.getName().equals(name)) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
480 |
throw new RuntimeException(this.getName() |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
481 |
+ ": Unexpected exception for "+name, x); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
482 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
483 |
throw x; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
484 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
485 |
l.fine("I'm fine"); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
486 |
if (!goOn) break; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
487 |
Thread.sleep(1); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
488 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
489 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
490 |
} catch (Exception x) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
491 |
fail(x); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
492 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
493 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
494 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
495 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
496 |
final static class DeadlockDetector extends Thread { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
497 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
498 |
@Override |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
499 |
public void run() { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
500 |
while(goOn) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
501 |
try { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
502 |
long[] ids = ManagementFactory.getThreadMXBean().findDeadlockedThreads(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
503 |
checkCount.incrementAndGet(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
504 |
ids = ids == null ? new long[0] : ids; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
505 |
if (ids.length == 1) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
506 |
throw new RuntimeException("Found 1 deadlocked thread: "+ids[0]); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
507 |
} else if (ids.length > 0) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
508 |
ThreadInfo[] infos = ManagementFactory.getThreadMXBean().getThreadInfo(ids); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
509 |
System.err.println("Found "+ids.length+" deadlocked threads: "); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
510 |
for (ThreadInfo inf : infos) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
511 |
System.err.println(inf.toString()); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
512 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
513 |
throw new RuntimeException("Found "+ids.length+" deadlocked threads"); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
514 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
515 |
Thread.sleep(100); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
516 |
} catch(InterruptedException | RuntimeException x) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
517 |
fail(x); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
518 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
519 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
520 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
521 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
522 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
523 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
524 |
static final class Stopper extends Thread { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
525 |
long start; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
526 |
long time; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
527 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
528 |
Stopper(long time) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
529 |
start = System.currentTimeMillis(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
530 |
this.time = time; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
531 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
532 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
533 |
@Override |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
534 |
public void run() { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
535 |
try { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
536 |
long rest, previous; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
537 |
previous = time; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
538 |
while (goOn && (rest = start - System.currentTimeMillis() + time) > 0) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
539 |
if (previous == time || previous - rest >= STEP) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
540 |
Logger.getLogger("remaining").info(String.valueOf(rest)+"ms remaining..."); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
541 |
previous = rest == time ? rest -1 : rest; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
542 |
System.gc(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
543 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
544 |
if (goOn == false) break; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
545 |
Thread.sleep(Math.min(rest, 100)); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
546 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
547 |
System.out.println(System.currentTimeMillis() - start |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
548 |
+ " ms elapsed ("+time+ " requested)"); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
549 |
goOn = false; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
550 |
} catch(InterruptedException | RuntimeException x) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
551 |
fail(x); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
552 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
553 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
554 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
555 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
556 |
|
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
557 |
static void fail(Exception x) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
558 |
x.printStackTrace(); |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
559 |
if (thrown == null) { |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
560 |
thrown = x; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
561 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
562 |
goOn = false; |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
563 |
} |
277d5c6b2172
8029281: Synchronization issues in Logger and LogManager
dfuchs
parents:
diff
changeset
|
564 |
} |