WEBVTT

00:00.870 --> 00:01.410
Hi everyone.

00:01.410 --> 00:02.670
Welcome back to this tutorial.

00:02.670 --> 00:06.480
In this tutorial, we will explore the parallel streams.

00:07.850 --> 00:09.320
What is a parallel stream?

00:09.350 --> 00:16.130
A parallel stream is something which is going to split the source data into multiple parts.

00:17.140 --> 00:23.350
And process them parallely and combine the result and give you the result as an output.

00:23.380 --> 00:26.110
That's what is called a parallel stream.

00:27.850 --> 00:29.200
How to create a parallel stream.

00:29.260 --> 00:31.720
Have an example here for a sequential stream.

00:31.720 --> 00:38.380
What it is doing here is that in stream dot range closed, it is going to create an empty stream of

00:38.500 --> 00:42.310
1000 elements and then it is going to perform a summation and return you.

00:42.310 --> 00:43.060
The result.

00:43.090 --> 00:49.120
If you do not call the parallel method explicitly, then that is a sequential stream.

00:50.610 --> 00:53.400
So this is an example for a parallel stream.

00:53.400 --> 00:59.160
What is happening here is as soon as we call the method parallel behind the scenes, what it is going

00:59.160 --> 01:04.660
to do, this is going to split the stream into multiple parts and process them concurrently.

01:04.680 --> 01:10.160
Basically, it is going to perform the summation concurrently on each and every part.

01:10.170 --> 01:15.180
It had split and then combine the result and give you the result as an output.

01:15.210 --> 01:17.670
Let's go ahead and explore this using an example.

01:19.800 --> 01:20.520
When to open the int.

01:21.090 --> 01:21.710
There you go.

01:21.780 --> 01:23.280
Have the open.

01:23.670 --> 01:32.610
We put this in full screen and in here what I'm going to do, I'm going to create a package called Parallel

01:33.450 --> 01:44.850
String and I'm going to create a class called Parallel stream example, parallel stream example.

01:46.650 --> 01:50.400
But let us make this class executable by adding public static void main.

01:51.180 --> 01:51.930
There you go.

01:52.380 --> 01:54.060
I'll put this in presentation mode.

01:55.200 --> 01:58.890
So I'm going to create two different methods.

01:58.890 --> 01:59.910
One is the.

02:01.570 --> 02:02.410
Some

02:04.420 --> 02:07.840
sequential cream.

02:11.090 --> 02:15.500
We are going to make this class a static one and it is going to return the result.

02:15.500 --> 02:16.070
Right?

02:16.070 --> 02:20.840
And then what the stream is going to do in stream dot range closed.

02:20.870 --> 02:23.750
I'm going to give the value as 100,000.

02:24.680 --> 02:26.240
And perform the sum.

02:29.640 --> 02:31.680
And we are going to return the result.

02:32.590 --> 02:33.070
Rate.

02:34.140 --> 02:36.210
Let's put the proper keyword here.

02:36.240 --> 02:37.080
Return keyword.

02:37.740 --> 02:42.120
And what I'm going to do, I'm going to create another method here.

02:42.120 --> 02:46.710
I'm going to name this one as some parallel string.

02:48.070 --> 02:48.640
Okay.

02:48.640 --> 02:49.750
So in here.

02:51.710 --> 02:56.730
I'm going to call this and check the result to find out whether both are giving us the same result or

02:56.730 --> 02:57.240
not.

03:01.610 --> 03:02.180
Going to be.

03:03.840 --> 03:09.780
Some parallel string and I'm going to run this example.

03:11.480 --> 03:12.190
You take a look at it.

03:12.190 --> 03:14.380
Both returned the same result.

03:14.680 --> 03:15.130
Right.

03:15.130 --> 03:18.890
But the idea is to find out which is performing better.

03:18.910 --> 03:19.620
Right.

03:19.630 --> 03:26.500
So we will explore how to check the performance of these two methods and compare which one is better

03:26.500 --> 03:27.930
in the next tutorial.

03:27.940 --> 03:30.010
With this, we came to the end of this tutorial.

03:30.010 --> 03:31.210
Thank you for watching.
