author | lana |
Tue, 23 May 2017 21:11:42 +0000 | |
changeset 45187 | 331a6542b5b8 |
parent 5959 | 3ff758c11233 |
permissions | -rw-r--r-- |
5959
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
1 |
/* |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
4 |
* |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
8 |
* |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
13 |
* accompanied this code). |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
14 |
* |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
18 |
* |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
21 |
* questions. |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
22 |
*/ |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
23 |
|
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
24 |
/* |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
25 |
* @test |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
26 |
* @bug 6963811 |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
27 |
* @summary Tests deadlock in Introspector |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
28 |
* @author Sergey Malenkov |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
29 |
*/ |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
30 |
|
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
31 |
import java.beans.Introspector; |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
32 |
import java.beans.SimpleBeanInfo; |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
33 |
|
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
34 |
public class Test6963811 implements Runnable { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
35 |
private final long time; |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
36 |
private final boolean sync; |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
37 |
|
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
38 |
public Test6963811(long time, boolean sync) { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
39 |
this.time = time; |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
40 |
this.sync = sync; |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
41 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
42 |
|
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
43 |
public void run() { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
44 |
try { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
45 |
Thread.sleep(this.time); // increase the chance of the deadlock |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
46 |
Introspector.getBeanInfo( |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
47 |
this.sync ? Super.class : Sub.class, |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
48 |
this.sync ? null : Object.class); |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
49 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
50 |
catch (Exception exception) { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
51 |
exception.printStackTrace(); |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
52 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
53 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
54 |
|
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
55 |
public static void main(String[] args) throws Exception { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
56 |
Thread[] threads = new Thread[2]; |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
57 |
for (int i = 0; i < threads.length; i++) { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
58 |
threads[i] = new Thread(new Test6963811(0L, i > 0)); |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
59 |
threads[i].start(); |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
60 |
Thread.sleep(500L); // increase the chance of the deadlock |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
61 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
62 |
for (Thread thread : threads) { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
63 |
thread.join(); |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
64 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
65 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
66 |
|
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
67 |
public static class Super { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
68 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
69 |
|
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
70 |
public static class Sub extends Super { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
71 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
72 |
|
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
73 |
public static class SubBeanInfo extends SimpleBeanInfo { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
74 |
public SubBeanInfo() { |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
75 |
new Test6963811(1000L, true).run(); |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
76 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
77 |
} |
3ff758c11233
6963811: Deadlock-prone locking changes in Introspector
malenkov
parents:
diff
changeset
|
78 |
} |