jdk/test/javax/swing/SwingWorker/6480289/bug6480289.java
changeset 7851 c4808ff47e60
parent 7850 ecd42a8e578e
parent 7837 518bf3de0840
child 7852 f1df06807698
equal deleted inserted replaced
7850:ecd42a8e578e 7851:c4808ff47e60
     1 /*
       
     2  * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
       
     3  * 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  * 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  */
       
    23 
       
    24 /* @test
       
    25  *
       
    26  * @bug 6480289
       
    27  * @author Igor Kushnirskiy
       
    28  * @summary tests if consequent workers are executed on the same thread and that VM can exit.
       
    29  */
       
    30 
       
    31 import java.util.*;
       
    32 import javax.swing.SwingWorker;
       
    33 
       
    34 public class bug6480289 {
       
    35     private static final int ITERATIONS = 5;
       
    36     private static final Map<Thread, Integer> threadMap =
       
    37         Collections.synchronizedMap(new HashMap<Thread, Integer>());
       
    38     public static void main(String[] args) throws Exception {
       
    39 
       
    40         for (int i = 0; i < ITERATIONS; i++) {
       
    41             if (i != 0) {
       
    42                 Thread.sleep(1000 * 5);
       
    43             }
       
    44             SwingWorker<?,?> worker =
       
    45                 new SwingWorker<Void, Void>() {
       
    46                     @Override
       
    47                     protected Void doInBackground() {
       
    48                         Integer value = threadMap.get(Thread.currentThread());
       
    49                         value = Integer.valueOf(
       
    50                             ((value == null) ? 0 : value.intValue())
       
    51                             + 1);
       
    52                         threadMap.put(Thread.currentThread(), value);
       
    53                         return null;
       
    54                     }
       
    55                 };
       
    56             worker.execute();
       
    57         }
       
    58         if (threadMap.keySet().size() != 1) {
       
    59             throw new RuntimeException("failed. More than one thread.");
       
    60         }
       
    61     }
       
    62 }