File tree Expand file tree Collapse file tree 2 files changed +11
-30
lines changed
test/jdk/com/sun/management/OperatingSystemMXBean Expand file tree Collapse file tree 2 files changed +11
-30
lines changed Original file line number Diff line number Diff line change 3434import jdk .test .lib .Platform ;
3535
3636public class GetProcessCpuLoad {
37+
38+ private static final int TEST_COUNT = 10 ;
39+
3740 public static void main (String [] argv ) throws Exception {
3841 OperatingSystemMXBean mbean = (com .sun .management .OperatingSystemMXBean )
3942 ManagementFactory .getOperatingSystemMXBean ();
4043
4144 Exception ex = null ;
42- double load ;
45+ int good = 0 ;
4346
44- for (int i = 0 ; i < 10 ; i ++) {
45- load = mbean .getProcessCpuLoad ();
47+ for (int i = 0 ; i < TEST_COUNT ; i ++) {
48+ double load = mbean .getProcessCpuLoad ();
4649 if (load == -1.0 && Platform .isWindows ()) {
47- // Some Windows 2019 systems can return -1 for the first few reads .
48- // Remember a -1 in case it never gets better .
50+ // Some Windows systems can return -1 occasionally, at any time .
51+ // Will fail if we never see good values .
4952 ex = new RuntimeException ("getProcessCpuLoad() returns " + load
5053 + " which is not in the [0.0,1.0] interval" );
5154 } else if (load < 0.0 || load > 1.0 ) {
@@ -54,6 +57,7 @@ public static void main(String[] argv) throws Exception {
5457 } else {
5558 // A good reading: forget any previous -1.
5659 ex = null ;
60+ good ++;
5761 }
5862 try {
5963 Thread .sleep (200 );
@@ -62,7 +66,8 @@ public static void main(String[] argv) throws Exception {
6266 }
6367 }
6468
65- if (ex != null ) {
69+ if (good == 0 ) {
70+ // Delayed failure for Windows.
6671 throw ex ;
6772 }
6873 }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments