mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-02 20:20:14 +00:00
8076050: java/lang/management/ThreadMXBean/ThreadMXBeanStateTest.java fails intermittently
Reviewed-by: sla
This commit is contained in:
parent
c3e9d85d31
commit
77b5a0e6c0
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2015 Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -28,6 +28,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
|
||||
import jdk.testlibrary.LockFreeLogManager;
|
||||
import jdk.testlibrary.Utils;
|
||||
|
||||
/**
|
||||
* ThreadStateController allows a thread to request this thread to transition
|
||||
@ -73,7 +74,7 @@ public class ThreadStateController extends Thread {
|
||||
|
||||
public static void pause(long ms) {
|
||||
try {
|
||||
Thread.sleep(ms);
|
||||
Thread.sleep(Utils.adjustTimeout(ms));
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@ -135,7 +136,7 @@ public class ThreadStateController extends Thread {
|
||||
try {
|
||||
// this thread has escaped the BLOCKED state
|
||||
// release the lock and a short wait before continue
|
||||
lock.wait(10);
|
||||
lock.wait(Utils.adjustTimeout(10));
|
||||
} catch (InterruptedException e) {
|
||||
// ignore
|
||||
interrupted.incrementAndGet();
|
||||
@ -165,7 +166,7 @@ public class ThreadStateController extends Thread {
|
||||
getId(), getName(), iterations.get(), interrupted.get());
|
||||
try {
|
||||
stateChange(nextState);
|
||||
lock.wait(10000);
|
||||
lock.wait(Integer.MAX_VALUE);
|
||||
log("%d: %s wakes up from timed waiting (iterations %d interrupted %d)%n",
|
||||
getId(), getName(), iterations.get(), interrupted.get());
|
||||
} catch (InterruptedException e) {
|
||||
@ -185,7 +186,8 @@ public class ThreadStateController extends Thread {
|
||||
case S_TIMED_PARKED: {
|
||||
log("%d: %s is going to timed park (iterations %d)%n",
|
||||
getId(), getName(), iterations.get());
|
||||
long deadline = System.currentTimeMillis() + 10000*1000;
|
||||
long deadline = System.currentTimeMillis() +
|
||||
Utils.adjustTimeout(10000*1000);
|
||||
stateChange(nextState);
|
||||
LockSupport.parkUntil(deadline);
|
||||
break;
|
||||
@ -195,7 +197,7 @@ public class ThreadStateController extends Thread {
|
||||
getId(), getName(), iterations.get(), interrupted.get());
|
||||
try {
|
||||
stateChange(nextState);
|
||||
Thread.sleep(1000000);
|
||||
Thread.sleep(Utils.adjustTimeout(1000000));
|
||||
} catch (InterruptedException e) {
|
||||
// finish sleeping
|
||||
interrupted.incrementAndGet();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -64,60 +64,61 @@ public class ThreadMXBeanStateTest {
|
||||
Thread.currentThread().getState();
|
||||
ThreadStateController thread = new ThreadStateController("StateChanger", globalLock);
|
||||
thread.setDaemon(true);
|
||||
|
||||
// before myThread starts
|
||||
thread.checkThreadState(NEW);
|
||||
|
||||
thread.start();
|
||||
thread.transitionTo(RUNNABLE);
|
||||
thread.checkThreadState(RUNNABLE);
|
||||
checkLockInfo(thread, RUNNABLE, null, null);
|
||||
|
||||
thread.suspend();
|
||||
ThreadStateController.pause(10);
|
||||
thread.checkThreadState(RUNNABLE);
|
||||
checkSuspendedThreadState(thread, RUNNABLE);
|
||||
thread.resume();
|
||||
|
||||
synchronized (globalLock) {
|
||||
thread.transitionTo(BLOCKED);
|
||||
thread.checkThreadState(BLOCKED);
|
||||
checkLockInfo(thread, BLOCKED,
|
||||
globalLock, Thread.currentThread());
|
||||
}
|
||||
|
||||
thread.transitionTo(WAITING);
|
||||
thread.checkThreadState(WAITING);
|
||||
checkLockInfo(thread, Thread.State.WAITING,
|
||||
globalLock, null);
|
||||
|
||||
thread.transitionTo(TIMED_WAITING);
|
||||
thread.checkThreadState(TIMED_WAITING);
|
||||
checkLockInfo(thread, TIMED_WAITING,
|
||||
globalLock, null);
|
||||
|
||||
|
||||
thread.transitionToPark(true /* timed park */);
|
||||
thread.checkThreadState(TIMED_WAITING);
|
||||
checkLockInfo(thread, TIMED_WAITING, null, null);
|
||||
|
||||
thread.transitionToPark(false /* indefinite park */);
|
||||
thread.checkThreadState(WAITING);
|
||||
checkLockInfo(thread, WAITING, null, null);
|
||||
|
||||
thread.transitionToSleep();
|
||||
thread.checkThreadState(TIMED_WAITING);
|
||||
checkLockInfo(thread, TIMED_WAITING, null, null);
|
||||
|
||||
thread.transitionTo(TERMINATED);
|
||||
thread.checkThreadState(TERMINATED);
|
||||
|
||||
try {
|
||||
System.out.println(thread.getLog());
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("TEST FAILED: Unexpected exception.");
|
||||
throw new RuntimeException(e);
|
||||
// before myThread starts
|
||||
thread.checkThreadState(NEW);
|
||||
|
||||
thread.start();
|
||||
thread.transitionTo(RUNNABLE);
|
||||
thread.checkThreadState(RUNNABLE);
|
||||
checkLockInfo(thread, RUNNABLE, null, null);
|
||||
|
||||
thread.suspend();
|
||||
ThreadStateController.pause(10);
|
||||
thread.checkThreadState(RUNNABLE);
|
||||
checkSuspendedThreadState(thread, RUNNABLE);
|
||||
thread.resume();
|
||||
|
||||
synchronized (globalLock) {
|
||||
thread.transitionTo(BLOCKED);
|
||||
thread.checkThreadState(BLOCKED);
|
||||
checkLockInfo(thread, BLOCKED,
|
||||
globalLock, Thread.currentThread());
|
||||
}
|
||||
|
||||
thread.transitionTo(WAITING);
|
||||
thread.checkThreadState(WAITING);
|
||||
checkLockInfo(thread, Thread.State.WAITING,
|
||||
globalLock, null);
|
||||
|
||||
thread.transitionTo(TIMED_WAITING);
|
||||
thread.checkThreadState(TIMED_WAITING);
|
||||
checkLockInfo(thread, TIMED_WAITING,
|
||||
globalLock, null);
|
||||
|
||||
|
||||
thread.transitionToPark(true /* timed park */);
|
||||
thread.checkThreadState(TIMED_WAITING);
|
||||
checkLockInfo(thread, TIMED_WAITING, null, null);
|
||||
|
||||
thread.transitionToPark(false /* indefinite park */);
|
||||
thread.checkThreadState(WAITING);
|
||||
checkLockInfo(thread, WAITING, null, null);
|
||||
|
||||
thread.transitionToSleep();
|
||||
thread.checkThreadState(TIMED_WAITING);
|
||||
checkLockInfo(thread, TIMED_WAITING, null, null);
|
||||
|
||||
thread.transitionTo(TERMINATED);
|
||||
thread.checkThreadState(TERMINATED);
|
||||
} finally {
|
||||
try {
|
||||
System.out.println(thread.getLog());
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("TEST FAILED: Unexpected exception.");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
System.out.println("Test passed.");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user