20- Solution- Random Delays
Jul 04, 2026 01:29
· 4:27
· English
· Whisper Turbo
· 2 স্পিকার
এই ট্রান্সক্রিপশন আজই শেষ হয়ে যাবে।
স্থায়ী সংরক্ষণের জন্য উন্নীত করুন →
শুধু দেখানো হচ্ছে
0:01
S…
Speaker 2 (20- Solution- Random Delays)
Now let's make this more interesting.
0:03
S…
Speaker 2 (20- Solution- Random Delays)
I'm going to add a random delay to each website.
0:05
S…
Speaker 2 (20- Solution- Random Delays)
I want each website to respond at a different time.
0:08
S…
Speaker 1 (20- Solution- Random Delays)
With this,
0:09
S…
Speaker 2 (20- Solution- Random Delays)
you can see that we're displaying these codes as we get them.
0:12
S…
Speaker 1 (20- Solution- Random Delays)
So,
0:13
S…
Speaker 2 (20- Solution- Random Delays)
let's go to our long task class.
0:17
S…
Speaker 2 (20- Solution- Random Delays)
I want to overwrite the simulate method,
0:21
S…
Speaker 2 (20- Solution- Random Delays)
and in the second version,
0:24
S…
Speaker 2 (20- Solution- Random Delays)
I want to introduce a parameter called delay.
0:28
S…
Speaker 2 (20- Solution- Random Delays)
So instead of three seconds,
0:29
S…
Speaker 2 (20- Solution- Random Delays)
we're going to use this argument.
0:32
S…
Speaker 2 (20- Solution- Random Delays)
Now we go to our flight service class.
0:34
S…
Speaker 2 (20- Solution- Random Delays)
We're going to reuse our random object to
0:38
S…
Speaker 2 (20- Solution- Random Delays)
pass a random delay to the simulate method.
0:42
S…
Speaker 2 (20- Solution- Random Delays)
So let's say we want each website to respond between 1 to 3
0:46
S…
Speaker 1 (20- Solution- Random Delays)
seconds.
0:47
S…
Speaker 2 (20- Solution- Random Delays)
We have a baseline of 1 second plus random
0:51
S…
Speaker 2 (20- Solution- Random Delays)
that next int 2 seconds.
0:54
S…
Speaker 2 (20- Solution- Random Delays)
Now let's run a program and see what happens.
0:57
S…
Speaker 2 (20- Solution- Random Delays)
So we're querying this concurrently and
1:01
S…
Speaker 2 (20- Solution- Random Delays)
We're getting responses in different times.
1:03
S…
Speaker 1 (20- Solution- Random Delays)
Beautiful.
1:04
S…
Speaker 2 (20- Solution- Random Delays)
Now the last part.
1:05
S…
Speaker 2 (20- Solution- Random Delays)
We want to print a final message to say how long it took to query all these
1:09
S…
Speaker 1 (20- Solution- Random Delays)
websites.
1:10
S…
Speaker 2 (20- Solution- Random Delays)
That is pretty easy.
1:11
S…
Speaker 2 (20- Solution- Random Delays)
So we go to our demo class.
1:13
S…
Speaker 1 (20- Solution- Random Delays)
After we get the quotes,
1:15
S…
Speaker 2 (20- Solution- Random Delays)
we collect them in a list.
1:17
S…
Speaker 2 (20- Solution- Random Delays)
Let's store the result over here.
1:19
S…
Speaker 2 (20- Solution- Random Delays)
This is going to give us a list of future objects.
1:23
S…
Speaker 2 (20- Solution- Random Delays)
Let me show you.
1:23
S…
Speaker 1 (20- Solution- Random Delays)
So,
1:24
S…
Speaker 2 (20- Solution- Random Delays)
list of completable future of void.
1:29
S…
Speaker 2 (20- Solution- Random Delays)
Now we can use the all of method to wait for the completion of all these
1:33
S…
Speaker 2 (20- Solution- Random Delays)
future objects.
1:33
S…
Speaker 1 (20- Solution- Random Delays)
So,
1:34
S…
Speaker 2 (20- Solution- Random Delays)
completable future dot all of,
1:37
S…
Speaker 2 (20- Solution- Random Delays)
here we have a var arcs parameter,
1:40
S…
Speaker 2 (20- Solution- Random Delays)
technically this is a syntactic sugar over arrays,
1:44
S…
Speaker 2 (20- Solution- Random Delays)
so we can pass an array of completable future objects.
1:47
S…
Speaker 2 (20- Solution- Random Delays)
That is pretty easy,
1:49
S…
Speaker 2 (20- Solution- Random Delays)
we call futures dot to array,
1:51
S…
Speaker 2 (20- Solution- Random Delays)
now this method is overloaded
1:53
S…
Speaker 2 (20- Solution- Random Delays)
The version without parameters returns an object array.
1:57
S…
Speaker 2 (20- Solution- Random Delays)
Let me show you.
1:57
S…
Speaker 2 (20- Solution- Random Delays)
I'm going to put this on a new line.
1:59
S…
Speaker 1 (20- Solution- Random Delays)
Take a look.
2:01
S…
Speaker 2 (20- Solution- Random Delays)
So the version without a parameter returns an object
2:05
S…
Speaker 2 (20- Solution- Random Delays)
array. We don't want this because the all of method expects an array
2:09
S…
Speaker 2 (20- Solution- Random Delays)
of completable future objects.
2:11
S…
Speaker 2 (20- Solution- Random Delays)
So we should use the second version and here we should pass an
2:15
S…
Speaker 2 (20- Solution- Random Delays)
array of completable futures.
2:17
S…
Speaker 1 (20- Solution- Random Delays)
With this,
2:18
S…
Speaker 2 (20- Solution- Random Delays)
we'll get a completable future array.
2:23
S…
Speaker 2 (20- Solution- Random Delays)
So over here we pass new completable future
2:27
S…
Speaker 2 (20- Solution- Random Delays)
of 0.
2:28
S…
Speaker 2 (20- Solution- Random Delays)
So we pass an empty array and with this we're telling
2:32
S…
Speaker 2 (20- Solution- Random Delays)
this method that we want the result to be a completable future array.
2:35
S…
Speaker 1 (20- Solution- Random Delays)
Okay?
2:36
S…
Speaker 2 (20- Solution- Random Delays)
Now we wait for all the result.
2:38
S…
Speaker 2 (20- Solution- Random Delays)
Let me put this on a new line.
2:41
S…
Speaker 2 (20- Solution- Random Delays)
Pay attention to how I'm formatting this code.
2:44
S…
Speaker 2 (20- Solution- Random Delays)
So we have completable future,
2:47
S…
Speaker 2 (20- Solution- Random Delays)
we wait for all these futures to complete,
2:49
S…
Speaker 2 (20- Solution- Random Delays)
then we're going to run
2:53
S…
Speaker 1 (20- Solution- Random Delays)
this piece of code.
2:54
S…
Speaker 2 (20- Solution- Random Delays)
This is where we're going to print our final message.
2:57
S…
Speaker 2 (20- Solution- Random Delays)
First we need to calculate how long it took to execute this operation.
3:00
S…
Speaker 1 (20- Solution- Random Delays)
So,
3:01
S…
Speaker 2 (20- Solution- Random Delays)
just before we start,
3:02
S…
Speaker 2 (20- Solution- Random Delays)
we're going to get the current time.
3:05
S…
Speaker 2 (20- Solution- Random Delays)
We can use the local time class.
3:08
S…
Speaker 2 (20- Solution- Random Delays)
This class has a static method called now.
3:11
S…
Speaker 2 (20- Solution- Random Delays)
So this returns the current time.
3:13
S…
Speaker 1 (20- Solution- Random Delays)
Now,
3:14
S…
Speaker 2 (20- Solution- Random Delays)
over here,
3:16
S…
Speaker 2 (20- Solution- Random Delays)
we're going to repeat this.
3:17
S…
Speaker 1 (20- Solution- Random Delays)
So,
3:18
S…
Speaker 2 (20- Solution- Random Delays)
we calculate the end time,
3:20
S…
Speaker 2 (20- Solution- Random Delays)
local time dot now.
3:23
S…
Speaker 2 (20- Solution- Random Delays)
Then we create a duration object.
3:25
S…
Speaker 2 (20- Solution- Random Delays)
So this duration class has a static method called between.
3:29
S…
Speaker 2 (20- Solution- Random Delays)
We can pass the start and end time and get
3:33
S…
Speaker 2 (20- Solution- Random Delays)
a duration object.
3:34
S…
Speaker 2 (20- Solution- Random Delays)
And finally we print a message like retrieve all
3:39
S…
Speaker 2 (20- Solution- Random Delays)
quotes in here we call duration dot
3:43
S…
Speaker 2 (20- Solution- Random Delays)
two millis.
3:45
S…
Speaker 2 (20- Solution- Random Delays)
This will return the duration in milliseconds.
3:47
S…
Speaker 2 (20- Solution- Random Delays)
And finally we add msec.
3:51
S…
Speaker 1 (20- Solution- Random Delays)
Okay?
3:53
S…
Speaker 2 (20- Solution- Random Delays)
Let's run the program and see the result.
3:55
S…
Speaker 1 (20- Solution- Random Delays)
There
4:02
S…
Speaker 1 (20- Solution- Random Delays)
you go.
4:02
S…
Speaker 1 (20- Solution- Random Delays)
Beautiful.
4:03
S…
Speaker 2 (20- Solution- Random Delays)
So that brings us to the end of this course.
4:05
S…
Speaker 2 (20- Solution- Random Delays)
I want to say thank you for allowing me to be your instructor.
4:08
S…
Speaker 2 (20- Solution- Random Delays)
If you enjoyed this course,
4:09
S…
Speaker 2 (20- Solution- Random Delays)
please support me by telling others about my coding school.
4:12
S…
Speaker 2 (20- Solution- Random Delays)
I really appreciate your support.
4:13
S…
Speaker 2 (20- Solution- Random Delays)
Once again,
4:15
S…
Speaker 2 (20- Solution- Random Delays)
thank you and I hope to see you again in my other courses.
4:17
S…
Speaker 2 (20- Solution- Random Delays)
Thank you and have a fantastic day.
এই ট্রান্সক্রিপশনটি AI (স্বয়ংক্রিয় বাক্য সনাক্তকরণ) দ্বারা তৈরি করা হয়েছে। এতে ভুল থাকতে পারে - গুরুত্বপূর্ণ ব্যবহারের জন্য মূল অডিওটির সাথে পরীক্ষা করুন। AI নীতিমালা
সারসংক্ষেপ
এই ট্রান্সক্রিপ্ট এর একটি AI সারসংক্ষেপ তৈরি করতে সারসংক্ষেপ ক্লিক করুন।
সারসংক্ষেপ...
এই ট্রান্সক্রিপ্ট সম্পর্কে AI জিজ্ঞাসা করুন
এই অনুলিপি সম্পর্কে যে কোন প্রশ্ন করুন - এআই সংশ্লিষ্ট অংশ খুঁজে বের করবে এবং উত্তর দেবে।