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