author | duke |
Wed, 05 Jul 2017 21:46:33 +0200 | |
changeset 38602 | b72e50a81d43 |
parent 27346 | 85050b6eea19 |
child 45192 | 3c481584b5a6 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
21637
diff
changeset
|
2 |
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
21614
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
24 |
import static java.lang.Thread.State.*; |
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
25 |
|
2 | 26 |
/* |
27 |
* @test |
|
21614
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
28 |
* @bug 5014783 8022208 |
2 | 29 |
* @summary Basic unit test of thread states returned by |
30 |
* Thread.getState(). |
|
31 |
* |
|
32 |
* @author Mandy Chung |
|
27346
85050b6eea19
8062896: TEST_BUG: java/lang/Thread/ThreadStateTest.java can't compile with change for 8058506
jbachorik
parents:
23010
diff
changeset
|
33 |
* @library /lib/testlibrary |
85050b6eea19
8062896: TEST_BUG: java/lang/Thread/ThreadStateTest.java can't compile with change for 8058506
jbachorik
parents:
23010
diff
changeset
|
34 |
* @build jdk.testlibrary.* |
21614
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
35 |
* @build ThreadStateTest ThreadStateController |
21219
0c61684d9606
7195597: ThreadStateTest gets different results with -Xcomp
morris
parents:
10065
diff
changeset
|
36 |
* @run main/othervm -Xmixed ThreadStateTest |
2 | 37 |
*/ |
38 |
||
39 |
public class ThreadStateTest { |
|
40 |
private static boolean testFailed = false; |
|
41 |
||
10065
f0dd422f49fa
7021010: java/lang/Thread/ThreadStateTest.java fails intermittently
chegar
parents:
5506
diff
changeset
|
42 |
// used to achieve waiting states |
21614
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
43 |
private static final Object globalLock = new Object(); |
2 | 44 |
|
21614
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
45 |
public static void main(String[] argv) throws Exception { |
2 | 46 |
// Call Thread.getState to force all initialization done |
47 |
// before test verification begins. |
|
48 |
Thread.currentThread().getState(); |
|
21614
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
49 |
ThreadStateController thread = new ThreadStateController("StateChanger", globalLock); |
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
50 |
thread.setDaemon(true); |
2 | 51 |
|
52 |
// before myThread starts |
|
21614
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
53 |
thread.checkThreadState(NEW); |
2 | 54 |
|
21614
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
55 |
thread.start(); |
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
56 |
thread.transitionTo(RUNNABLE); |
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
57 |
thread.checkThreadState(RUNNABLE); |
2 | 58 |
|
59 |
synchronized (globalLock) { |
|
21614
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
60 |
thread.transitionTo(BLOCKED); |
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
61 |
thread.checkThreadState(BLOCKED); |
2 | 62 |
} |
63 |
||
21614
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
64 |
thread.transitionTo(WAITING); |
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
65 |
thread.checkThreadState(WAITING); |
2 | 66 |
|
21614
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
67 |
thread.transitionTo(TIMED_WAITING); |
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
68 |
thread.checkThreadState(TIMED_WAITING); |
2 | 69 |
|
21614
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
70 |
thread.transitionToPark(true /* timed park*/); |
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
71 |
thread.checkThreadState(TIMED_WAITING); |
2 | 72 |
|
21614
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
73 |
thread.transitionToPark(false /* indefinite park */); |
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
74 |
thread.checkThreadState(WAITING); |
2 | 75 |
|
21614
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
76 |
thread.transitionToSleep(); |
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
77 |
thread.checkThreadState(TIMED_WAITING); |
2 | 78 |
|
21614
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
79 |
thread.transitionTo(TERMINATED); |
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
80 |
thread.checkThreadState(TERMINATED); |
2 | 81 |
|
82 |
try { |
|
21614
c7336876755e
8022208: Intermittent test failures in java/lang/Thread/ThreadStateTest.java
mchung
parents:
10065
diff
changeset
|
83 |
thread.join(); |
2 | 84 |
} catch (InterruptedException e) { |
85 |
e.printStackTrace(); |
|
86 |
System.out.println("Unexpected exception."); |
|
87 |
testFailed = true; |
|
88 |
} |
|
10065
f0dd422f49fa
7021010: java/lang/Thread/ThreadStateTest.java fails intermittently
chegar
parents:
5506
diff
changeset
|
89 |
|
2 | 90 |
if (testFailed) |
91 |
throw new RuntimeException("TEST FAILED."); |
|
92 |
System.out.println("Test passed."); |
|
93 |
} |
|
94 |
} |