ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/jtreg/util/Collections/ViewSynch.java
Revision: 1.4
Committed: Mon Jan 8 03:12:03 2018 UTC (6 years, 4 months ago) by jsr166
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +5 -1 lines
Log Message:
organize imports

File Contents

# User Rev Content
1 jsr166 1.1 /*
2 jsr166 1.2 * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
3 jsr166 1.1 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4     *
5     * This code is free software; you can redistribute it and/or modify it
6     * under the terms of the GNU General Public License version 2 only, as
7     * published by the Free Software Foundation.
8     *
9     * This code is distributed in the hope that it will be useful, but WITHOUT
10     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11     * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12     * version 2 for more details (a copy is included in the LICENSE file that
13     * accompanied this code).
14     *
15     * You should have received a copy of the GNU General Public License version
16     * 2 along with this work; if not, write to the Free Software Foundation,
17     * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18     *
19 jsr166 1.2 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20     * or visit www.oracle.com if you need additional information or have any
21     * questions.
22 jsr166 1.1 */
23    
24 jsr166 1.3 /*
25 jsr166 1.1 * @test
26     * @bug 4268780
27     * @summary Collection-views of submap-views of synchronized-views of
28     * SortedMap objects do not synchronize on the correct object.
29     * (Got that?)
30     */
31    
32 jsr166 1.4 import java.util.Collection;
33     import java.util.Collections;
34     import java.util.Map;
35     import java.util.SortedMap;
36     import java.util.TreeMap;
37 jsr166 1.1
38     public class ViewSynch {
39     static final Integer ZERO = new Integer(0);
40     static final Int INT_ZERO = new Int(0);
41     static final Int INT_ONE = new Int(1);
42     static SortedMap m = Collections.synchronizedSortedMap(new TreeMap());
43     static Map m2 = m.tailMap(ZERO);
44     static Collection c = m2.values();
45    
46     public static void main(String[] args) {
47     for (int i=0; i<10000; i++)
48     m.put(new Integer(i), INT_ZERO);
49    
50     new Thread() {
51     public void run() {
52     for (int i=0; i<100; i++) {
53     Thread.yield();
54     m.remove(ZERO);
55     m.put(ZERO, INT_ZERO);
56     }
57     }
58     }.start();
59    
60     c.contains(INT_ONE);
61     }
62     }
63    
64     /**
65     * Like Integer, except yields while doing equals comparison, to allow
66     * for interleaving.
67     */
68     class Int {
69     Integer x;
70     Int(int i) {x = new Integer(i);}
71    
72     public boolean equals(Object o) {
73     Thread.yield();
74     Int i = (Int)o;
75     return x.equals(i.x);
76     }
77    
78     public int hashCode() {return x.hashCode();}
79     }