Java Tutorials - Herong's Tutorial Examples - v8.22, by Herong Yang
Application Data Shared by Multiple Threads - Test Results
This section provides test results of a tutorial example on how to share application data by multiple threads. Data sharing allows multiple threads to work together on a single large task.
I performed several tests with the program presented in the previous section. Testing outputs are listed below.
Test on a new computer with 8 CPUs/processors and n_loop = 50:
Output of 4000 years and 1 thread:
herong> java WeekDayCounter 4000 1 Thread: 0 Year: 0 Year: 2043 Year: 2340 ... Year: 5932 Year: 5999 Time = 1413 Thread #, Years 0, 4000 Total # of years = 4000
Output of 4000 years and 4 thread:
herong> java WeekDayCounter 4000 4 Thread: 0 1 2 3 Year: 0 0 0 0 Year: 0 0 0 0 Year: 2032 2033 2031 2034 Year: 2312 2328 2327 2331 ... Year: 5919 5929 5928 5927 Year: 5999 5999 5999 5999 Time = 746 Thread #, Years 0, 1073 1, 1014 2, 958 3, 958 Total # of years = 4003
Output of 4000 years and 8 thread:
herong> java WeekDayCounter 4000 8 Thread: 0 1 2 3 4 5 6 7 Year: 0 0 0 0 0 0 0 0 Year: 2014 2039 2061 2086 2092 2097 2132 2114 Year: 2346 2487 2640 2826 3025 3051 3269 3285 Year: 4933 5031 5039 5270 5327 5438 5483 5649 Year: 5999 5999 5999 5999 5999 5999 5999 5999 Time = 812 Thread #, Years 0, 489 1, 506 ... 6, 513 7, 511 Total # of years = 4003
Output of 4000 years and 16 thread:
herong> java WeekDayCounter 4000 16 Thread: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Year: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Year: 2040 2033 2034 2029 2023 2032 2036 2022 2042 2037 2020 2041 2045 ... Year: 2171 2167 2176 2174 2166 2178 2172 2170 2165 2175 2169 2177 2179 ... Year: 2375 2482 2514 2816 3166 3647 3908 4453 4849 5115 5686 5785 5912 ... Year: 5999 5999 5999 5999 5999 5999 5999 5999 5999 5999 5999 5999 5999 ... Time = 1006 Thread #, Years 0, 281 1, 286 ... 14, 255 15, 200 Total # of years = 4003
A couple of interesting notes on the results:
Test on an old computer with 1 CPU/processor and n_loop = 1:
Output of 2000 years and 1 thread:
Thread: 0 Year: 0 Year: 2001 Year: 2025 ... Year: 3966 Year: 3999 Time = 6029 ...
Output of 2000 years and 5 threads:
Thread: 0 1 2 3 4 Year: 0 0 0 0 0 Year: 2039 2040 2043 2042 2044 Year: 2067 2040 2048 2042 2044 ... Year: 3992 3999 3999 3999 3999 Year: 3999 3999 3999 3999 3999 Time = 6369 ...
Output of 2000 years and 10 threads:
Thread: 0 1 2 3 4 5 6 7 8 9 Year: 2936 2948 3237 3242 3208 2954 3182 3232 3169 2963 Year: 2936 3303 3237 3242 3208 3272 3182 3232 3169 2963 Year: 3495 3498 3237 3480 3974 3890 3996 3999 3999 2963 Year: 3999 3999 3999 3999 3999 3999 3999 3999 3999 3999 Time = 3925 ...
Output of 2000 years and 10 threads - another run:
Thread: 0 1 2 3 4 5 6 7 8 9 Year: 2222 2239 2174 2275 2245 2142 2213 0 0 2248 Year: 2531 2283 2501 2510 2245 2142 2213 2460 2521 2470 Year: 2531 2283 2583 2624 2547 2142 2213 2460 2556 2615 ... Year: 3908 3949 3890 3978 3937 3991 3625 3396 3745 3426 Year: 3999 3999 3999 3999 3999 3999 3999 3999 3999 3999 Time = 6750 ...
Output of 2000 years and 15 threads:
Thread: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Year: 2039 2046 2053 0 0 0 0 0 0 0 0 2284 2363 2425 2387 Year: 2212 2499 2088 0 0 0 0 0 0 0 0 2284 2489 2461 2387 Year: 2638 2655 2088 0 0 0 0 2615 2663 2645 2602 2630 2489 2461 2387 Year: 3441 2885 2088 2921 3430 3169 3487 2903 3362 3222 3186 3499 ... Year: 3996 3841 3502 3836 3611 3815 3999 3501 3362 3993 3900 3885 ... Year: 3999 3999 3999 3999 3999 3999 3999 3999 3999 3999 3999 3999 ... Time = 6920 ...
A couple of interesting notes on the results:
Table of Contents
Execution Process, Entry Point, Input and Output
Primitive Data Types and Literals
Bits, Bytes, Bitwise and Shift Operations
Managing Bit Strings in Byte Arrays
Reference Data Types and Variables
StringBuffer - The String Buffer Class
System Properties and Runtime Object Methods
Generic Classes and Parameterized Types
Generic Methods and Type Inference
Lambda Expressions and Method References
Java Modules - Java Package Aggregation
►Execution Threads and Multi-Threading Java Programs
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
ThreadGroup Class and "system" ThreadGroup Tree
Synchronization Technique and Synchronized Code Blocks
Deadlock Condition Example Programs
Garbage Collection and the gc() Method
Assert Statements and -ea" Option