blob: a9c15049bb922ccc4b08763883c5dd432be15ec9 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any 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
31import java.util.*;
32import javax.swing.SwingWorker;
33
34public 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}