author | amurillo |
Wed, 15 Aug 2012 16:49:38 -0700 | |
changeset 13465 | d3fc5d192448 |
parent 12694 | 543c5e6c5ed0 |
child 14856 | 92a1bcf46888 |
permissions | -rw-r--r-- |
12694
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
1 |
/* |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
2 |
* Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. |
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 |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
32 |
* @author Deven You |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
33 |
*/ |
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 |
import java.util.Properties; |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
36 |
import sun.management.Agent; |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
37 |
|
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
38 |
public class AgentCMETest { |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
39 |
static Class<?> agentClass; |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
40 |
|
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 |
* In sun.management.Agent.loadManagementProperties(), call |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
43 |
* 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
|
44 |
* 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
|
45 |
* |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
46 |
* @param args |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
47 |
* @throws Exception |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
48 |
*/ |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
49 |
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
|
50 |
System.out.println("Start..."); |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
51 |
|
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
52 |
final Properties properties = System.getProperties(); |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
53 |
Thread t1 = new Thread(new Runnable() { |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
54 |
public void run() { |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
55 |
for (int i = 0; i < 100; i++) { |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
56 |
properties.put(String.valueOf(i), ""); |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
57 |
try { |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
58 |
Thread.sleep(1); |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
59 |
} catch (InterruptedException e) { |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
60 |
// do nothing |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
61 |
} |
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 |
t1.start(); |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
66 |
|
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
67 |
for (int i = 0; i < 10000; i++) { |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
68 |
Agent.loadManagementProperties(); |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
69 |
} |
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 |
System.out.println("Finished..."); |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
72 |
} |
543c5e6c5ed0
7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents:
diff
changeset
|
73 |
} |