jdk/test/sun/management/AgentCMETest.java
author darcy
Thu, 13 Aug 2015 21:46:05 -0700
changeset 32147 5f6d9917598c
parent 30376 2ccf2cf7ea48
permissions -rw-r--r--
8133588: Place TimeoutLockLoops.java on the problem list Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12694
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
     1
/*
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 14856
diff changeset
     2
 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
12694
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
     4
 *
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
     7
 * published by the Free Software Foundation.
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
     8
 *
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    13
 * accompanied this code).
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    14
 *
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    18
 *
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    21
 * questions.
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    22
 */
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    23
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    24
/*
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    25
 * Portions Copyright (c) 2012 IBM Corporation
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    26
 */
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    27
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    28
/**
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    29
 * @test
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    30
 * @bug 7164191
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    31
 * @summary properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 14856
diff changeset
    32
 * @modules java.management/sun.management
12694
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    33
 * @author Deven You
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    34
 */
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    35
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    36
import java.util.Properties;
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    37
import sun.management.Agent;
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    38
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    39
public class AgentCMETest {
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    40
    static Class<?> agentClass;
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    41
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    42
    /**
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    43
     * In sun.management.Agent.loadManagementProperties(), call
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    44
     * properties.putAll API may fail with ConcurrentModifcationException if the
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    45
     * system properties are modified simultaneously by another thread
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    46
     *
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    47
     * @param args
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    48
     * @throws Exception
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    49
     */
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    50
    public static void main(String[] args) throws Exception {
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    51
        System.out.println("Start...");
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    52
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    53
        final Properties properties = System.getProperties();
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    54
        Thread t1 = new Thread(new Runnable() {
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    55
            public void run() {
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    56
                for (int i = 0; i < 100; i++) {
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    57
                    properties.put(String.valueOf(i), "");
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    58
                    try {
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    59
                        Thread.sleep(1);
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    60
                    } catch (InterruptedException e) {
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    61
                        // do nothing
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    62
                    }
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    63
                }
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    64
            }
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    65
        });
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    66
        t1.start();
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    67
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    68
        for (int i = 0; i < 10000; i++) {
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    69
            Agent.loadManagementProperties();
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    70
        }
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    71
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    72
        System.out.println("Finished...");
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    73
    }
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff changeset
    74
}