I have below out put from one of VM.
So, as per link, the parallel streams use the default ForkJoinPool.commonPool
which by default has one less threads as you have processors, as returned by Runtime.getRuntime().availableProcessors()
.
If I do Runtime.getRuntime().availableProcessors()
, then it always returns 1, but looking at below output, number should have been more.
What I am missing here?
lscpu command output is :-
2019-02-05T20:20:33.813+05:30 [APP/PROC/WEB/0] [OUT] Architecture: x86_64
2019-02-05T20:20:33.813+05:30 [APP/PROC/WEB/0] [OUT] CPU op-mode(s): 32-bit, 64-bit
2019-02-05T20:20:33.813+05:30 [APP/PROC/WEB/0] [OUT] Byte Order: Little Endian
2019-02-05T20:20:33.813+05:30 [APP/PROC/WEB/0] [OUT] CPU(s): 4
2019-02-05T20:20:33.813+05:30 [APP/PROC/WEB/0] [OUT] On-line CPU(s) list: 0-3
2019-02-05T20:20:33.814+05:30 [APP/PROC/WEB/0] [OUT] Thread(s) per core: 1
2019-02-05T20:20:33.814+05:30 [APP/PROC/WEB/0] [OUT] Core(s) per socket: 1
2019-02-05T20:20:33.819+05:30 [APP/PROC/WEB/0] [OUT] Socket(s): 4
2019-02-05T20:20:33.819+05:30 [APP/PROC/WEB/0] [OUT] NUMA node(s): 1
2019-02-05T20:20:33.819+05:30 [APP/PROC/WEB/0] [OUT] Vendor ID: GenuineIntel
2019-02-05T20:20:33.819+05:30 [APP/PROC/WEB/0] [OUT] CPU family: 6
2019-02-05T20:20:33.819+05:30 [APP/PROC/WEB/0] [OUT] Model: 58
2019-02-05T20:20:33.819+05:30 [APP/PROC/WEB/0] [OUT] Stepping: 0
2019-02-05T20:20:33.820+05:30 [APP/PROC/WEB/0] [OUT] CPU MHz: 2599.998
2019-02-05T20:20:33.820+05:30 [APP/PROC/WEB/0] [OUT] BogoMIPS: 5199.99
2019-02-05T20:20:33.820+05:30 [APP/PROC/WEB/0] [OUT] Hypervisor vendor: VMware
2019-02-05T20:20:33.820+05:30 [APP/PROC/WEB/0] [OUT] Virtualization type: full
2019-02-05T20:20:33.820+05:30 [APP/PROC/WEB/0] [OUT] L1d cache: 32K
2019-02-05T20:20:33.820+05:30 [APP/PROC/WEB/0] [OUT] L1i cache: 32K
2019-02-05T20:20:33.821+05:30 [APP/PROC/WEB/0] [OUT] L2 cache: 256K
2019-02-05T20:20:33.821+05:30 [APP/PROC/WEB/0] [OUT] L3 cache: 40960K
As you can see parallel stream used all 4 CPU cores to perform computation.
Java Parallel Streams is a feature of Java 8 and higher, meant for utilizing multiple cores of the processor. Normally any java code has one stream of processing, where it is executed sequentially.
Parallel streams divide the provided task into many and run them in different threads, utilizing multiple cores of the computer. On the other hand sequential streams work just like for-loop using a single core.
You are most likely running the Java code inside a VM with limited number of vCPUs or in a container restricted by control groups (cgroups) while your lscpu
command is run on the host machine.
Unless your JVM is affected by a bug (e.g. JDK-8188310 or JDK-6515172), these numbers should be the same.
Do note that Java 10 improved resource management as per Java Improvements for Docker Containers and introduced -XX:ActiveProcessorCount
option. Javas 8 that you are currently using definitely doesn't handle all edge cases correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With