The more efficient Java threads have always been, and then know the efficiency of execution and CPU core number, today we tried the multi-core CPU under multithreading calculation:
This machine i5 four cores, opens 1, 4, 10, 20, 40, 100, 400 threads to do 100W times respectively, the result is as follows:
All tasks completed, total time consuming: 38368ms,threadsize:1,section:1000000
All Tasks completed, total time consuming: 17293ms,threadsize:4,section:250000
All tasks completed, total time consuming: 15107ms,threadsize:10,section:100000
All Tasks completed, total time consuming: 15019ms,threadsize:20,section:50000
All tasks completed, total time consuming: 16115ms,threadsize:40,section:25000
All Tasks completed, total time consuming: 22014ms,threadsize:100,section:10000
All tasks completed, total time consuming: 40431ms,threadsize:400,section:2500
Threadsize is the number of concurrent threads, and the section is the MD5 of each thread.
The number of threads is most efficient between 10-20
CPU Usage:
Single Thread:
4 Threads:
10 Threads:
20 Threads:
40 Threads:
100 Threads:
400 Threads:
As shown in the figure:
1. Single threaded processes can also lead to a rise in the usage of multiple CPUs, supposedly because a single thread is crowding out the CPU resources of other processes on the system, causing these system processes to increase overhead on other CPUs.
2. In 10-20 threads, the CPU's rise is smooth and stable, and hundreds of threads, CPU usage fluctuations are relatively large, may be the frequent task scheduling caused.