Path: blob/master/test/jdk/java/util/Locale/Bug6989440.java
41149 views
/*1* Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 698944026* @summary Verify ConcurrentModificationException is not thrown with multiple27* thread accesses.28* @modules java.base/sun.util.locale.provider29* @compile -XDignore.symbol.file=true Bug6989440.java30* @run main Bug698944031*/32import java.text.spi.DateFormatProvider;33import java.util.spi.LocaleNameProvider;34import java.util.spi.LocaleServiceProvider;35import java.util.spi.TimeZoneNameProvider;3637import sun.util.locale.provider.LocaleServiceProviderPool;3839public class Bug6989440 {40static volatile boolean failed; // false41static final int THREADS = 50;4243public static void main(String[] args) throws Exception {44Thread[] threads = new Thread[THREADS];45for (int i=0; i<threads.length; i++)46threads[i] = new TestThread();47for (int i=0; i<threads.length; i++)48threads[i].start();49for (int i=0; i<threads.length; i++)50threads[i].join();5152if (failed)53throw new RuntimeException("Failed: check output");54}5556static class TestThread extends Thread {57private Class<? extends LocaleServiceProvider> cls;58private static int count;5960public TestThread(Class<? extends LocaleServiceProvider> providerClass) {61cls = providerClass;62}6364public TestThread() {65int which = count++ % 3;66switch (which) {67case 0 : cls = LocaleNameProvider.class; break;68case 1 : cls = TimeZoneNameProvider.class; break;69case 2 : cls = DateFormatProvider.class; break;70default : throw new AssertionError("Should not reach here");71}72}7374public void run() {75try {76LocaleServiceProviderPool pool = LocaleServiceProviderPool.getPool(cls);77pool.getAvailableLocales();78} catch (Exception e) {79System.out.println(e);80e.printStackTrace();81failed = true;82}83}84}85}868788