Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/util/Locale/Bug6989440.java
41149 views
1
/*
2
* Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 6989440
27
* @summary Verify ConcurrentModificationException is not thrown with multiple
28
* thread accesses.
29
* @modules java.base/sun.util.locale.provider
30
* @compile -XDignore.symbol.file=true Bug6989440.java
31
* @run main Bug6989440
32
*/
33
import java.text.spi.DateFormatProvider;
34
import java.util.spi.LocaleNameProvider;
35
import java.util.spi.LocaleServiceProvider;
36
import java.util.spi.TimeZoneNameProvider;
37
38
import sun.util.locale.provider.LocaleServiceProviderPool;
39
40
public class Bug6989440 {
41
static volatile boolean failed; // false
42
static final int THREADS = 50;
43
44
public static void main(String[] args) throws Exception {
45
Thread[] threads = new Thread[THREADS];
46
for (int i=0; i<threads.length; i++)
47
threads[i] = new TestThread();
48
for (int i=0; i<threads.length; i++)
49
threads[i].start();
50
for (int i=0; i<threads.length; i++)
51
threads[i].join();
52
53
if (failed)
54
throw new RuntimeException("Failed: check output");
55
}
56
57
static class TestThread extends Thread {
58
private Class<? extends LocaleServiceProvider> cls;
59
private static int count;
60
61
public TestThread(Class<? extends LocaleServiceProvider> providerClass) {
62
cls = providerClass;
63
}
64
65
public TestThread() {
66
int which = count++ % 3;
67
switch (which) {
68
case 0 : cls = LocaleNameProvider.class; break;
69
case 1 : cls = TimeZoneNameProvider.class; break;
70
case 2 : cls = DateFormatProvider.class; break;
71
default : throw new AssertionError("Should not reach here");
72
}
73
}
74
75
public void run() {
76
try {
77
LocaleServiceProviderPool pool = LocaleServiceProviderPool.getPool(cls);
78
pool.getAvailableLocales();
79
} catch (Exception e) {
80
System.out.println(e);
81
e.printStackTrace();
82
failed = true;
83
}
84
}
85
}
86
}
87
88