Java Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 6.00

CPU Execution Time Shared by Multiple Threads - Test Output

This section provides the test output of a tutorial example on how to measuring CPU execution time allocated to threads with different setPriorities.

I executed the program presented in the previous section on my Windows 2000 system, and got the following output.

Priority: (min, norm, max) = (1, 5, 10)
Threads: 0 1 2 3 4 Time
  Steps: 1527 2229 161931 31864 29386 17416
  Steps: 3193 3881 175188 44342 41757 20301
  Steps: 6499 5536 204244 74234 71608 27221
  Steps: 8164 10495 244791 114110 112329 36475
  Steps: 11491 10495 257239 142209 139702 43025
  Steps: 13157 13805 285516 154633 152887 45909
  Steps: 14820 15458 297916 167948 165368 48793
  Steps: 16484 18763 327732 197825 195242 59009
  Steps: 19817 22073 369925 239372 236753 65448
  Steps: 23150 23729 403986 273273 271592 73410
  Steps: 26482 27018 416407 286531 284058 76295
  Steps: 28127 27018 429632 298998 296468 79299
  Steps: 29794 31993 473677 343808 341381 89575
  Steps: 33118 33662 486954 371226 368753 95944
  Steps: 34780 35317 514379 397811 395301 102193
  Steps: 38109 38639 541010 410201 408616 104958
  Steps: 39770 40305 553411 423504 421101 111027
  Steps: 41433 43640 595710 465923 463501 117757
  Steps: 44763 45310 609007 478306 493386 124557
  Steps: 48096 46980 638029 508055 519042 130686
  Steps: 49759 50313 664613 533784 531442 133570
  Steps: 51424 53649 690265 560371 558010 139639
  Steps: 53090 53649 720171 589434 587953 146550
  Steps: 58088 58656 751803 620981 619626 157366
  Steps: 64759 65335 819279 688363 687045 169324
  Steps: 68092 70339 865085 734088 732079 183085
  Steps: 74763 73680 914229 783060 782025 191217
  Steps: 78097 78691 958380 827074 826209 201372
  Steps: 81431 82033 999999 871975 870174 211036
  Steps: 86439 87032 999999 924273 923406 219149
  Steps: 91446 92023 999999 999999 999999 230506
  Steps: 91446 93361 999999 999999 999999 230626
  Steps: 91446 94721 999999 999999 999999 230726
  Steps: 91446 96091 999999 999999 999999 230826
  Terminate batch job (Y/N)? y  

Here is what I get out of the output of the program:

  • Threads with the different priority levels may get the same amount of processing time share. See the progresses of thread 0 and 1. Thread 0 had priority 1, and thread 1 had priority 5. But they showed about the same progress rate.
  • Thread of priority 1 was getting about 10 times less amount of the processing time share than thread of priority 10. See the progress rates of thread 0 and thread 4.
  • The main thread was running at least 20 times slower when all 5 sub-threads were running. See the elapse time intervals, which were > 2000 milliseconds while all 5 sub-threads were running. The sleeping time was about 100 milliseconds. So the main thread was blocked for at least 1900 milliseconds.

Another interesting behavior was noticed while executing the program. While all 5 sub-threads were running, the operating system was very sluggish. I was only able to move the mouse pointer around. Clicking on windows of any other running application programs gave me no response at all until 3 sub-threads reached the end. I guess the reason for this behavior is that Windows 2000 system is not truly sharing processing time among the running application programs equally. It let my Java application program (running under Java VM) took 100% of the CPU processing time. This is not a well-designed time-sharing multi-tasking operating system. Can anyone try my program a Unix system?

Sections in This Chapter

What Are Processes and Threads?

The "Thread" Class - Creating Thread Objects With Thread Sub Classes

The "Runnable" Interface - Creating Thread Objects with Runnable Objects

CPU Execution Time Shared by Multiple Threads

CPU Execution Time Shared by Multiple Threads - Test Output

Application Data Shared by Multiple Threads

Application Data Shared by Multiple Threads - Test Results

interrupt() - Method to Terminate Thread

Dr. Herong Yang, updated in 2008
CPU Execution Time Shared by Multiple Threads - Test Output