WEBVTT

00:00.770 --> 00:01.250
Hi everyone.

00:01.250 --> 00:02.480
Welcome back to this tutorial.

00:02.480 --> 00:07.940
In this tutorial, we will explore how parallel stream works behind the scenes.

00:08.390 --> 00:14.000
Parallel Stream uses the fork join framework under the hood to process the streams.

00:14.000 --> 00:15.500
Parallelly and the fork.

00:15.500 --> 00:19.850
Join framework got introduced as part of Java seven.

00:20.090 --> 00:27.230
Fork join creates multiple threads for you, but the question here is how many threads that gets created.

00:27.350 --> 00:33.650
The number of threads that gets created is equal to the number of processors that are available in the

00:33.650 --> 00:34.490
machine.

00:34.490 --> 00:41.630
The main reason for this way of spawning the threads is the advancement of technology in the world today.

00:41.660 --> 00:46.010
Today, even smartphones that you have in your hand has multiple processors.

00:46.010 --> 00:52.640
The idea is to use those resources available to perform the concurrent processing.

00:52.640 --> 00:57.620
Let's go ahead and check how many processors are available in this machine.

00:58.220 --> 01:07.190
I'm going to go to the IntelliJ and then what I'm going to do, I'm going to do a Sis out and run time

01:07.190 --> 01:11.570
dot get runtime dot available processors.

01:11.570 --> 01:19.820
So this is going to give you how many processors are available in this machine run.

01:19.820 --> 01:26.930
This is going to give you the value here as eight So this machine has eight processors.

01:26.930 --> 01:32.900
So as soon as this parallel method call happened and then because the terminal operation is the one

01:32.900 --> 01:38.120
which is going to start the whole pipeline as soon as the some method is called and it checks, okay.

01:38.150 --> 01:40.910
Is it a parallel stream or a sequential stream?

01:40.910 --> 01:50.150
If it is a parallel stream, this is going to split the data into multiple parts and process them concurrently

01:51.710 --> 01:56.600
and it is going to accumulate the result and give you the result as a output.

01:56.600 --> 02:01.470
I would like to show you what happens behind the scenes using using the presentation here.

02:02.010 --> 02:06.210
So if you go here, this machine has eight processors.

02:06.210 --> 02:07.440
That's what we checked here.

02:07.440 --> 02:13.920
So sequential stream, what it is going to do, it is going to perform the complete summation operation

02:13.920 --> 02:15.450
using one processor.

02:15.450 --> 02:21.060
It is not going to leverage the multiple processors that you have in your machine.

02:21.060 --> 02:27.090
But in the case of parallel stream, this is going to split the whole data source into multiple parts

02:27.090 --> 02:30.990
and then assign each part to a processor.

02:30.990 --> 02:35.250
And this processor is going to take care of performing the summation for you.

02:35.250 --> 02:41.490
Parallelly And towards the end it is going to sum all the result and give you the result as a output.

02:41.490 --> 02:48.150
So this is all about what happens behind the scenes when you call the parallel stream method.

02:49.990 --> 02:50.470
With this.

02:50.470 --> 02:52.120
We came to the end of this tutorial.

02:52.150 --> 02:53.380
Thank you for watching.
