jdk/test/java/awt/Window/AlwaysOnTop/SyncAlwaysOnTopFieldTest.java
author martin
Wed, 02 Sep 2015 14:11:50 -0700
changeset 32427 c22b7e41adf3
parent 27766 e3dd9610de38
child 39056 d99e63b6d962
permissions -rw-r--r--
8134984: Text files should end in exactly one newline Summary: automated fixup of newlines at end-of-file via the usual perl one-liner Reviewed-by: chegar, sherman
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27766
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
     1
/*
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
     4
 *
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
     8
 *
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    13
 * accompanied this code).
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    14
 *
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    18
 *
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    21
 * questions.
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    22
 */
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    23
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    24
import java.awt.Window;
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    25
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    26
/**
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    27
 * @test
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    28
 * @bug 8064468
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    29
 * @author Alexander Scherbatiy
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    30
 * @summary ownedWindowList access requires synchronization in
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    31
 *     Window.setAlwaysOnTop() method
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    32
 * @run main SyncAlwaysOnTopFieldTest
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    33
 */
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    34
public class SyncAlwaysOnTopFieldTest {
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    35
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    36
    private static final int WINDOWS_COUNT = 200;
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    37
    private static final int STEPS_COUNT = 20;
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    38
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    39
    public static void main(String[] args) throws Exception {
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    40
        final Window rootWindow = createWindow(null);
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    41
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    42
        new Thread(() -> {
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    43
            for (int i = 0; i < WINDOWS_COUNT; i++) {
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    44
                createWindow(rootWindow);
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    45
            }
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    46
        }).start();
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    47
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    48
        boolean alwaysOnTop = true;
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    49
        for (int i = 0; i < STEPS_COUNT; i++) {
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    50
            Thread.sleep(10);
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    51
            rootWindow.setAlwaysOnTop(alwaysOnTop);
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    52
            alwaysOnTop = !alwaysOnTop;
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    53
        }
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    54
    }
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    55
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    56
    private static Window createWindow(Window parent) {
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    57
        Window window = new Window(parent);
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    58
        window.setSize(200, 200);
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    59
        window.setVisible(true);
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    60
        return window;
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents:
diff changeset
    61
    }
32427
c22b7e41adf3 8134984: Text files should end in exactly one newline
martin
parents: 27766
diff changeset
    62
}