test/compiler/6772683/InterruptedTest.java

Thu, 11 Apr 2013 09:39:57 -0700

author
katleman
date
Thu, 11 Apr 2013 09:39:57 -0700
changeset 4883
5dcfeb396fed
parent 1907
c18cbe5936b8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Added tag jdk8-b85 for changeset 42fe530cd478

kvn@1222 1 /*
trims@1907 2 * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
kvn@1222 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
kvn@1222 4 *
kvn@1222 5 * This code is free software; you can redistribute it and/or modify it
kvn@1222 6 * under the terms of the GNU General Public License version 2 only, as
kvn@1222 7 * published by the Free Software Foundation.
kvn@1222 8 *
kvn@1222 9 * This code is distributed in the hope that it will be useful, but WITHOUT
kvn@1222 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
kvn@1222 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kvn@1222 12 * version 2 for more details (a copy is included in the LICENSE file that
kvn@1222 13 * accompanied this code).
kvn@1222 14 *
kvn@1222 15 * You should have received a copy of the GNU General Public License version
kvn@1222 16 * 2 along with this work; if not, write to the Free Software Foundation,
kvn@1222 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
kvn@1222 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
kvn@1222 22 *
kvn@1222 23 */
kvn@1222 24
kvn@1222 25 /*
kvn@1222 26 * @test
kvn@1222 27 * @bug 6772683
kvn@1222 28 * @summary Thread.isInterrupted() fails to return true on multiprocessor PC
kvn@1222 29 * @run main/othervm InterruptedTest
kvn@1222 30 */
kvn@1222 31
kvn@1222 32 public class InterruptedTest {
kvn@1222 33
kvn@1222 34 public static void main(String[] args) throws Exception {
kvn@1222 35 Thread workerThread = new Thread("worker") {
kvn@1222 36 public void run() {
kvn@1222 37 System.out.println("Worker thread: running...");
kvn@1222 38 while (!Thread.currentThread().isInterrupted()) {
kvn@1222 39 }
kvn@1222 40 System.out.println("Worker thread: bye");
kvn@1222 41 }
kvn@1222 42 };
kvn@1222 43 System.out.println("Main thread: starts a worker thread...");
kvn@1222 44 workerThread.start();
kvn@1222 45 System.out.println("Main thread: waits at most 5s for the worker thread to die...");
kvn@1222 46 workerThread.join(5000); // Wait 5 sec to let run() method to be compiled
kvn@1222 47 int ntries = 0;
kvn@1222 48 while (workerThread.isAlive() && ntries < 5) {
kvn@1222 49 System.out.println("Main thread: interrupts the worker thread...");
kvn@1222 50 workerThread.interrupt();
kvn@1222 51 if (workerThread.isInterrupted()) {
kvn@1222 52 System.out.println("Main thread: worker thread is interrupted");
kvn@1222 53 }
kvn@1222 54 ntries++;
kvn@1222 55 System.out.println("Main thread: waits for the worker thread to die...");
kvn@1222 56 workerThread.join(1000); // Wait 1 sec and try again
kvn@1222 57 }
kvn@1222 58 if (ntries == 5) {
kvn@1222 59 System.out.println("Main thread: the worker thread dod not die");
kvn@1222 60 System.exit(97);
kvn@1222 61 }
kvn@1222 62 System.out.println("Main thread: bye");
kvn@1222 63 }
kvn@1222 64
kvn@1222 65 }

mercurial