Path: blob/master/test/jdk/java/net/ProxySelector/MultiThreadedSystemProxies.java
41149 views
/*1* Copyright (c) 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*/22/*23* @test24* @bug 718875525* @run main/othervm MultiThreadedSystemProxies26* @summary Crash due to missing synchronization on gconf_client in27* DefaultProxySelector.c28*/29import java.net.ProxySelector;30import java.net.URI;3132/* Racey test, not guaranteed to fail, but if it does we have a problem. */3334public class MultiThreadedSystemProxies {35static final int NUM_THREADS = 100;3637public static void main(String[] args) throws Exception {38System.setProperty("java.net.useSystemProxies", "true");39final ProxySelector ps = ProxySelector.getDefault();40final URI uri = new URI("http://ubuntu.com");41Thread[] threads = new Thread[NUM_THREADS];4243for (int i = 0; i < NUM_THREADS; i++) {44threads[i] = new Thread(new Runnable() {45@Override46public void run() {47try {48ps.select(uri);49} catch (Exception x) {50throw new RuntimeException(x);51}52}53});54}55for (int i = 0; i < NUM_THREADS; i++) {56threads[i].start();57}58for (int i = 0; i < NUM_THREADS; i++) {59threads[i].join();60}61}62}636465