Path: blob/master/test/jdk/java/util/Properties/CheckUnsynchronized.java
41149 views
/*1* Copyright (c) 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*/2223import java.util.Enumeration;24import java.util.Properties;25import java.util.concurrent.CompletableFuture;2627/*28* @test29* @bug 802989130* @summary Test Properties methods that do not synchronize any more31* @run main CheckUnsynchronized32*/33public class CheckUnsynchronized {34public static void main(String[] args) {35Properties props = new Properties();36synchronized (props) {37props.setProperty("key", "value");38System.out.println("contains(value)? " +39CompletableFuture.supplyAsync(() -> props.contains("value")).join());40System.out.println("containsKey(key)? " +41CompletableFuture.supplyAsync(() -> props.containsKey("key")).join());42System.out.println("containsValue(value)? " +43CompletableFuture.supplyAsync(() -> props.containsValue("value")).join());44Enumeration<Object> elems =45CompletableFuture.supplyAsync(() -> props.elements()).join();46System.out.println("first value from elements(): " + elems.nextElement());47System.out.println("value from get(): " +48CompletableFuture.supplyAsync(() -> props.getProperty("key")).join());49System.out.println("getOrDefault(\"missing\"): " +50CompletableFuture.supplyAsync(() -> props.getOrDefault("missing", "default")).join());51System.out.println("isEmpty()? " +52CompletableFuture.supplyAsync(() -> props.isEmpty()).join());53Enumeration<Object> keys =54CompletableFuture.supplyAsync(() -> props.keys()).join();55System.out.println("first key from keys(): " + keys.nextElement());56System.out.println("size(): " +57CompletableFuture.supplyAsync(() -> props.size()).join());58}59}60}616263