Path: blob/master/test/jdk/java/security/Security/SynchronizedAccess.java
41149 views
/*1* Copyright (c) 1999, 2016, 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 4162583 7054918 813018126* @library ../testlibrary27* @summary Make sure Provider api implementations are synchronized properly28*/2930import java.security.*;3132public class SynchronizedAccess {3334public static void main(String[] args) throws Exception {35ProvidersSnapshot snapshot = ProvidersSnapshot.create();36try {37main0(args);38} finally {39snapshot.restore();40}41}4243public static void main0(String[] args) throws Exception {44AccessorThread[] acc = new AccessorThread[200];45for (int i=0; i < acc.length; i++)46acc[i] = new AccessorThread("thread"+i);47for (int i=0; i < acc.length; i++)48acc[i].start();49for (int i=0; i < acc.length; i++)50acc[i].join();51}52}5354class AccessorThread extends Thread {5556public AccessorThread(String str) {57super(str);58}5960public void run() {61Provider[] provs = new Provider[10];62for (int i=0; i < provs.length; i++)63provs[i] = new MyProvider("name"+i, "1", "test");6465int rounds = 20;66while (rounds-- > 0) {67try {68for (int i=0; i<provs.length; i++) {69Security.addProvider(provs[i]);70}71Signature sig = Signature.getInstance("sigalg");72for (int i=0; i<provs.length; i++) {73Security.removeProvider("name"+i);74}75provs = Security.getProviders();76} catch (NoSuchAlgorithmException nsae) {77}7879try {80Thread.sleep(5);81} catch (InterruptedException ie) {82}83} // while84}85}8687class MyProvider extends Provider {88public MyProvider(String name, String version, String info) {89super(name, version, info);90put("Signature.sigalg", "sigimpl");91}92}939495