Java 8 CompletableFuture Tutorial Part-2 | thenApply(), thenAccept() & ThenRun() | JavaTechie

  Рет қаралды 32,949

Java Techie

Java Techie

Күн бұрын

In this tutorial we will understand how You can attach a callback to the CompletableFuture using thenApply(), thenAccept() and thenRun() methods
#javatechie #Java8 #CompletableFuture @Multithreading
GitHub:
github.com/Jav...
Blogs:
/ javatechie
Facebook:
/ 919464521471923
guys if you like this video please do subscribe now and press the bell icon to not miss any update from Java Techie
Disclaimer/Policy:
--------------------------------
Note : All uploaded content in this channel is mine and its not copied from any community ,
you are free to use source code from above mentioned GitHub account

Пікірлер: 177
@rohitchobharkar747
@rohitchobharkar747 3 ай бұрын
Waiting for next session @Java Techie
@TheEntium
@TheEntium 2 жыл бұрын
Truly amazing.. the way you explain is like a flow of river.. with to the point example .. this is really what I love your examples..... really appreciated your hard work brother that you put on every videos .. please continue this Completablefuture series to the end.. Once again thank you brother.. keep growing
@malayasinha414
@malayasinha414 Жыл бұрын
Implemented CompletableFuture in one of my spring boot service just by seeing only your video and now it is working absolutely perfect. Thanks a tonne.
@pinpaigurung3654
@pinpaigurung3654 2 жыл бұрын
Waiting for third session Sir. Thank you
@kavyasudhakar
@kavyasudhakar Ай бұрын
Please make part-3 of this series.
@sandeep_begudem
@sandeep_begudem 10 ай бұрын
Thank you Basanth for the wonderful presentation, it would be really great if you do a part -3 and demo the process for combining multiple CompletableFuture threads.
@shanashafkat
@shanashafkat 9 ай бұрын
Never thought coding can be so peaceful. You are beyond anything and above everything Thank you for this amazing piece
@jvivekanand7875
@jvivekanand7875 2 жыл бұрын
Great explination sir, waiting for your third session. Thank you very much.
@venuparva
@venuparva 2 жыл бұрын
Very nice video...Please share Part-3 link with .thencompose() n other functionalities...Really appreciate your effort towards it...Thanks a lot for your service :)
@mahimakaushal7381
@mahimakaushal7381 2 жыл бұрын
Awesome learning always from Java Techie
@MuraliM.A.
@MuraliM.A. 3 ай бұрын
Nice video, please create part 3 on this
@gauravvijan03
@gauravvijan03 2 жыл бұрын
Eagerly waiting for your next tutorial for the same series
@rakibulhasan1923
@rakibulhasan1923 2 жыл бұрын
you are always excellent as a teacher ,as a human being...salute
@foddiebyage9696
@foddiebyage9696 2 жыл бұрын
Pls continue such important topics in Java including testing and database queries
@subhrajeetpadhy
@subhrajeetpadhy 2 жыл бұрын
Awesome explanation and I can see your hard work. Please release the third session for combining thread results.
@vinodnayak27
@vinodnayak27 Жыл бұрын
I really enjoyed part1 and 2 great content 😍. can you please make part 3 as well.
@LokeshMawale87
@LokeshMawale87 8 ай бұрын
Nice video and very well explained Basant. Can you please add exception handling part for the same. It will be very useful
@Javatechie
@Javatechie 8 ай бұрын
Sure Lokesh
@ainigma100
@ainigma100 3 ай бұрын
Thank you for the amazing video! Can you please upload Part 3 as well
@shanashafkat
@shanashafkat 8 ай бұрын
Hey @javatechie, I could not thank you enough for these videos. Please release PART 3 video.
@Javatechie
@Javatechie 8 ай бұрын
I will do part 3 since i found very less response in this content so i stopped it in middle
@shivangiubarhande3276
@shivangiubarhande3276 8 ай бұрын
@@Javatechie Please prepare part 3 waiting for it. You are excellent at this !!
@Javatechie
@Javatechie 8 ай бұрын
Noted and will try to close in next weekend for sure
@kumaresanperumal2581
@kumaresanperumal2581 2 жыл бұрын
Thanks.
@ILuvBilli
@ILuvBilli 2 жыл бұрын
Very nice and clear explanation, waiting for 3rd part
@cooldude20able
@cooldude20able 2 жыл бұрын
Amazing explanation and hard work, please release the further videos soon 😄
@abhaymishra8112
@abhaymishra8112 2 жыл бұрын
Thanks to explain very clearly. Please create a video on thenCombine() & thenCompose()
@satyabatigoswami1735
@satyabatigoswami1735 6 ай бұрын
waiting for third part 😇Great content !
@jianwenliu458
@jianwenliu458 2 жыл бұрын
This is awesome, thank you, looking for the release of the further videos
@akhilthammishetty3097
@akhilthammishetty3097 Жыл бұрын
Here independent code from all the apply methods is executing first i.e print statements ,we can see SOP statements are being printed first, so this way multithreading is being achieved.
@7thwik
@7thwik Жыл бұрын
yes, each of them are executing in a separate, but it doesn't have much of use, because each thenApply() method is dependent on the output of the previous thenApply().
@user-ez4fz2oq1c
@user-ez4fz2oq1c 6 ай бұрын
Pls make 3 part it's very useful
@harshverm776
@harshverm776 5 ай бұрын
Yes, Please
@deepaksetia461
@deepaksetia461 2 жыл бұрын
very nice explanation brother, waiting for next part.
@ThePomelo09
@ThePomelo09 2 жыл бұрын
your tutorials are awesome, excellent teacher
@NaveenSaisri
@NaveenSaisri 2 жыл бұрын
Your content and explanation is awesome, please do the Part-3 of completableFuture
@SANDIPKUMAR-es7qh
@SANDIPKUMAR-es7qh 11 ай бұрын
Thanks for crearing such a informative video, waiting for part3
@Javatechie
@Javatechie 11 ай бұрын
Okay i will do that
@SANDIPKUMAR-es7qh
@SANDIPKUMAR-es7qh 11 ай бұрын
​@@Javatechiethank you😊
@pradeepjain1889
@pradeepjain1889 2 жыл бұрын
Grt , impressive . Create NEXT video
@swapnilmedhe6679
@swapnilmedhe6679 2 жыл бұрын
Simply awesome @ Java Techie appriciate your efforts
@maheswarbehera1
@maheswarbehera1 2 жыл бұрын
Nice explanation on CompletableFuture. Please proceed with some other methods if possible.
@SyedIbrahimMohamedIsmail
@SyedIbrahimMohamedIsmail Жыл бұрын
Thank you so much. please help us with more real time examples for any of your forth coming videos.
@salehhassan6057
@salehhassan6057 2 жыл бұрын
I have read books and seen many videos about this topic. Nothing of them has helped as much as yours done. You are amazing. Thanks a lot Waiting for part 3...
@Javatechie
@Javatechie 2 жыл бұрын
Thanks will add part 3 . Since I uploaded 2 video but didn't get positive response so stopped it . But anyway I will complete 3rd one .
@salehhassan6057
@salehhassan6057 2 жыл бұрын
@@Javatechie Thanks a lot 😇❤
@salmanbaig3582
@salmanbaig3582 Жыл бұрын
@@Javatechie Please Sir upload Part 3 also. These videos are gems. Amazing thank you so much
@Javatechie
@Javatechie Жыл бұрын
Okay will do that
@salmanbaig3582
@salmanbaig3582 Жыл бұрын
@@Javatechie 🙏🙏thank you
@SandeepAS-ov3fk
@SandeepAS-ov3fk Жыл бұрын
simply amazing...
@myakhandbharat-2024
@myakhandbharat-2024 Жыл бұрын
awesome Job !! Waiting for your third part , if you already have it then please share the link
@ManishKumar-qx1kh
@ManishKumar-qx1kh 2 жыл бұрын
sir can you please create a playlist of DSA and Spring Beginner to Expert it will help a lot of people. Really appreciate the way you explain.
@rahimkhan-fh9dd
@rahimkhan-fh9dd 2 жыл бұрын
Great video basant
@narraleelakrishnavasavi9757
@narraleelakrishnavasavi9757 2 жыл бұрын
This is so helpful, could you please cover remaining concepts also
@sivagdvs6884
@sivagdvs6884 2 жыл бұрын
Hi bro. Please continue the series
@Javatechie
@Javatechie 2 жыл бұрын
Will do that
@sanathrayala2745
@sanathrayala2745 Ай бұрын
waiting for the next session Basanth please complete the series
@pratishrutipanda6461
@pratishrutipanda6461 2 жыл бұрын
Nice content 👍
@dhruvwadhwa9259
@dhruvwadhwa9259 4 ай бұрын
Waiting for next session
@firewater1045
@firewater1045 2 жыл бұрын
Very nice
@PradeepKumar-db7pe
@PradeepKumar-db7pe 7 ай бұрын
Thanks @JavaTechie! One Question- Using customThreadPool; should be slow in performance considering there will be multiple context switching among threads. Whereas in case of fork join pool, all the task being executed by single thread only i.e no context switching. I think It doesn’t make sense having multi-threads when tasks are interdependent like in this case. But yes making use of thenXxx is awesome. Thanks for your explanation!
@manojtailor2683
@manojtailor2683 Жыл бұрын
Even we are using multiple threads to complete the whole task, arent they executing in sequence because next thread depends on the output of first thread?
@AbhaySingh-ds9et
@AbhaySingh-ds9et 2 жыл бұрын
Hi @JavaTechie Please make video on ThenCompose and thencombine and exception handling as well and also cover all.topics will be very helpful for all subscribers. Always you create some awesome content..kind of your job only thanks.
@Javatechie
@Javatechie 2 жыл бұрын
Sure abhay will do that
@AbhaySingh-ds9et
@AbhaySingh-ds9et 2 жыл бұрын
@@Javatechie Hoping will receive it soon. Thanks
@AmritAgarwal07
@AmritAgarwal07 Жыл бұрын
Super content
@vaibhavlodha5398
@vaibhavlodha5398 Жыл бұрын
Thank you for the video this is a great explanation. Question: Seems like all these tasks will only run serially since next thread depends on the completion of the previous thread. Trying to understand how would the usage of thenApplyAsync be helpful here ?
@ikramfaruqui4093
@ikramfaruqui4093 2 жыл бұрын
very helpful
@random-characters4162
@random-characters4162 Жыл бұрын
thank you very much sir!
@harshverm776
@harshverm776 5 ай бұрын
Thanks
@sujitkumar2196
@sujitkumar2196 Жыл бұрын
Good Explanation bro...so when we can expect next tutorial.
@jagabandhujena9476
@jagabandhujena9476 Жыл бұрын
Hi sir..,waiting for part 3 video, plz upload 3rd part, many thanks...
@Javatechie
@Javatechie Жыл бұрын
Okay buddy I will do that
@sivadara5677
@sivadara5677 9 ай бұрын
@JavaTechie, Hi Sir Can you please do video on allOf, thenCompose etc call back functions so that it would be very helpful for us sir ..
@Javatechie
@Javatechie 9 ай бұрын
Okay i will
@sivadara5677
@sivadara5677 9 ай бұрын
@@Javatechie thank you sir .. I am watching and practicing all your videos both Java, angular and devops to become FSE Sir.. My sincere thanks to you sir for all you are doing for us..I have cleared 3 interviews by watching your classes only..You are my God sir..🙏🙏🙏
@AnuragTripathiShiva
@AnuragTripathiShiva 19 күн бұрын
Hi Basant, First of all thanks for your extremely and informative videos on every concept of java & microservices. I am bit curios in case of suppyAsynch(), when we have provided executor with 5 threads. But It seems like when we use thenApply(), each subsequent task is dependent on previous one. So, how this can be achieved or run by multiple threads. Correct me if I am wrong.
@pnworks9186
@pnworks9186 Жыл бұрын
Thank you Sir. this is very helpfull
@varunvijaywargi5497
@varunvijaywargi5497 Жыл бұрын
Hi, this is simply an amazing tutorial. However, I have a question that I'm confused about. If we have provided our own executor with 5 threads, then since each of the "thenApplyAsynch" is based on the outcome of a previous one (I.e first get pending training employees, get their email and then send email), will it not be a problem? Or how does it improve performance here? Also, another question is how does concurrent executiion and multi threading work on a container based environment?
@dmitrikonnov922
@dmitrikonnov922 Жыл бұрын
Great question. I wonder likewise.
@7thwik
@7thwik Жыл бұрын
Yes, even I have the same question. If each of thenApply() is dependent on the output of the previous thenApply() method, then what is the use here. Even though it executes in a separate thread, it still needs to wait for the other thread to complete its execution. This is a bad example to demonstrate multithreading I feel.
@swagatrath2256
@swagatrath2256 3 ай бұрын
Good explanation of the concept. My doubt - are we really achieving any parallelism here though? since each part of the task is being executed only when the previous one is done and each one of them runs on a single thread. So is it not same as writing the complete logic line by line in a main() and let it execute sequentially?
@tejamanu6690
@tejamanu6690 2 жыл бұрын
Basant, one small request could you please start a series on Kafka event driven architecture(EDA).
@Javatechie
@Javatechie 2 жыл бұрын
Okay I will
@spaul1408
@spaul1408 Жыл бұрын
I really enjoyed Part 1 and Part 2..Amazing content.. Can you please make part 3?
@Javatechie
@Javatechie Жыл бұрын
Okay sure i will do that
@sumitarora2554
@sumitarora2554 8 ай бұрын
@@Javatechieyes please share part 3 video also
@mohammedshabbir1347
@mohammedshabbir1347 2 жыл бұрын
Great video basant. Can you also please create videos on other topics of completable future. I can only see 2 videos on completable furure in your java8 play list.
@murugansivaraj7340
@murugansivaraj7340 2 жыл бұрын
Just a doubt here, what is the point in having thenApplyAsync() here, because anyway every task has to wait for the previous task to be completed. So It really doesn't matter if we run it in one thread or multiple threads. Multi threading comes to play when one task does not really depend on the other.
@Javatechie
@Javatechie 2 жыл бұрын
No purpose of this method to expect return type from other thread then process it . To verify you can pass your custom ExecutorService
@zurumogbonda3225
@zurumogbonda3225 Жыл бұрын
Good lecture as always.. please is the 3rd one out?
@AshishYadav-se4db
@AshishYadav-se4db 2 жыл бұрын
Amazing content Sir, I was waiting for this, thanks alot sir 🙏❤️
@vishnudasmankar8387
@vishnudasmankar8387 Жыл бұрын
Waiting for your third session sir
@priyabratprasadmohapatra363
@priyabratprasadmohapatra363 2 жыл бұрын
Please if you can make a video on the complete evolution of Java multithreading till Java 8 or above.
@Javatechie
@Javatechie 2 жыл бұрын
Will do
@prashhanthnelakanti4992
@prashhanthnelakanti4992 2 жыл бұрын
This video was very helpful and could be better if there is time complexity also involved
@Javatechie
@Javatechie 2 жыл бұрын
You are talking about code time complexity
@prashhanthnelakanti4992
@prashhanthnelakanti4992 2 жыл бұрын
@@Javatechie I mean the time taken by the thread to finish the task ...something like that
@rakeshjalui9063
@rakeshjalui9063 Жыл бұрын
Could you please share part-3 video link, which will cover other topics thenCompose, allOf(), anyOf() you mentioned at the end of part-2 video?
@karthickkumar4150
@karthickkumar4150 2 жыл бұрын
Hi Sir, Thanks for explaining the details clearly. Can you tell me how to handle exception while doing this asynchronous calls.
@Javatechie
@Javatechie 2 жыл бұрын
Yes i will cover that
@nareshrudroju4943
@nareshrudroju4943 7 ай бұрын
Please release 3rd session
@AbhaySingh-ds9et
@AbhaySingh-ds9et 2 жыл бұрын
@JavaTechie Have one question here in this example is the call is asynchronous and one thread is not waiting for other thread to complete its task. Because all steps defines seem to be depend. Can you provide some explanation will be great.
@Javatechie
@Javatechie 2 жыл бұрын
Okay 👍
@AbhaySingh-ds9et
@AbhaySingh-ds9et 2 жыл бұрын
Can you please answer this questions.
@nikhileshyoutube4924
@nikhileshyoutube4924 2 жыл бұрын
Bro create a video on java learning path brother for beginners it will be worth from developers like you
@shubhamjumde9076
@shubhamjumde9076 2 жыл бұрын
Hi, this video is very helpful ! Can we have any video series for Consul and Vault with Microservices and Spring Boot . Also , can we cover inter services communication in Microservices architecture with ActiveMQ? Please consider.
@Javatechie
@Javatechie 2 жыл бұрын
Hi Subham , please check out my both spring boot and microservices playlist, all above mentioned concepts already covered
@shubhamjumde9076
@shubhamjumde9076 2 жыл бұрын
@@Javatechie Thank you ! 😀
@kelvintsangxxx7581
@kelvintsangxxx7581 2 жыл бұрын
thx
@abhis1560
@abhis1560 Жыл бұрын
Waiting for third session. Please start one soon.
@Javatechie
@Javatechie Жыл бұрын
Will upload buddy
@narayanreddy7449
@narayanreddy7449 2 жыл бұрын
Amazing content, can you please do one tutorial on groupby and partitionby using streams
@Javatechie
@Javatechie 2 жыл бұрын
Okay I will definitely try this
@harishhari1310
@harishhari1310 Жыл бұрын
Thanks for the tutorial. in my use case i want 3 methods to be executed concurrently & the output needs to be binded together. could you please suggest
@arunbhandari5132
@arunbhandari5132 4 ай бұрын
What is the benefit of using multiple threads if they are happening in synchronize manner?
@Javatechie
@Javatechie 3 ай бұрын
It's not processed in synchronously please check I shown the results with sopln statement
@Sharma.Shivam
@Sharma.Shivam Жыл бұрын
good explanation I have one question Executors.newCachedThreadPool() versus Executors.newFixedThreadPool() can you elaborate please
@zamirdr
@zamirdr 2 жыл бұрын
Thankyou for a very clear tutorial, can you tell me how can I use exceptionally key word between tasks you showed here so if one service/task fails like fetching from DB then we can execute fallback method?
@ajisegirisunday2885
@ajisegirisunday2885 2 жыл бұрын
Nice work.. Can we use completetablefuture with stream parallels? Like parallelstream().map(). Thanks
@Javatechie
@Javatechie 2 жыл бұрын
Didn't get you
@ajisegirisunday2885
@ajisegirisunday2885 2 жыл бұрын
@@Javatechie I mean after getting the data from db when applying the then Applyasync method can we use parallel streams instead of the ordinary stream before mapping the data
@swatimalik9752
@swatimalik9752 2 жыл бұрын
I have one doubt, as supplyAsync() used when we have to return something, why the return type here is CompletableFuture ? This was suitable for runAsync ().
@Javatechie
@Javatechie 2 жыл бұрын
You can change your return type as per your requirement please checkout my first video . Here I just want to show demo of future chaing so didn't specify return type
@flowchart5471
@flowchart5471 2 жыл бұрын
Waiting for third part Basant.
@learnamazingtech3694
@learnamazingtech3694 2 жыл бұрын
Even though it’s executed by different threads it’s executing sequentially
@Javatechie
@Javatechie 2 жыл бұрын
No add a print statement and also keep your executor
@dipakramole
@dipakramole 2 жыл бұрын
Waiting for part 3
@18ajai
@18ajai 2 жыл бұрын
Whats the use of thenApplyAsync in this example. Even if each step is running in a different thread but each thread is still waiting for the output of previous step to execute. So will it make a difference in perfoemance?
@Javatechie
@Javatechie 2 жыл бұрын
Very poor response guys. Based on your demand I am preparing content but really disappointed with you guys feedback. Anyway keep learning and share
@santhoshshetty4500
@santhoshshetty4500 2 жыл бұрын
Its a great series Basant, please continue
@abdus_samad890
@abdus_samad890 2 жыл бұрын
Liked your video friend... Very nice...
@darkknightgotham2172
@darkknightgotham2172 2 жыл бұрын
please complete the series
@Hariprasadization
@Hariprasadization 4 ай бұрын
Waiting for part3
@kavyasudhakar
@kavyasudhakar Ай бұрын
Waiting for part-3
@Maddy4645
@Maddy4645 2 жыл бұрын
Could you please make video regarding intellj Ide It could be helpful for us Basant
@oldaccount137
@oldaccount137 2 жыл бұрын
Here one future is depending on other because without returning how other task will do it's processing , then what is the use of Asynchronous programming . Can u please explain it more clearly because supplyAsync when return the value then only we can proceed furthur so it is dependent on some other task . Also explain all other methods of completable future
@Javatechie
@Javatechie 2 жыл бұрын
Yes correct buddy but Here the context is to chain multiple future together . There is no way in java to unblock completely while working on multi threading
@krishnendughosh1212
@krishnendughosh1212 2 жыл бұрын
Hi Basant, Thanks for this excellent video . Had 1 question , How can we create an asynchronous thread for each iteration in a loop and join those at the end ?
@akashkharade2259
@akashkharade2259 Жыл бұрын
Thanks for such a beautiful explanation. Is part 3 released? If yes please give link for that
@Javatechie
@Javatechie Жыл бұрын
No it's not released
@LeoLeo-nx5gi
@LeoLeo-nx5gi Жыл бұрын
@@Javatechie I hope you check this comment, we are eagerly waiting for the next series on this, thanks a ton ^_^
@Javatechie
@Javatechie Жыл бұрын
Buddy I check and will try to publish asap
@LeoLeo-nx5gi
@LeoLeo-nx5gi Жыл бұрын
@@Javatechie thanks for your reply and support!!
@abhishekwasave9010
@abhishekwasave9010 2 жыл бұрын
How can we securely shutdown executor when using supplasync with thenrun ?
@GVB438
@GVB438 2 жыл бұрын
Can we use this to return jpa data or export data into file is there any best example
@Javatechie
@Javatechie 2 жыл бұрын
Offcourse why not
@buenasdias786
@buenasdias786 2 жыл бұрын
Please add further videos sir
@chilukabharath4809
@chilukabharath4809 2 жыл бұрын
nice video, but in this use case we can fetch direct emails from db by writing all those conditions in a single shot, with out writing multiple tasks. can you give me any other use case, or ignore if my question is wrong..
@Javatechie
@Javatechie 2 жыл бұрын
Yes buddy I could fetch all emails directly using query but in video to explained future chaing I took this example
@jedans3437
@jedans3437 15 күн бұрын
Third session?
@Chaloobolo
@Chaloobolo Жыл бұрын
Hey do you have any paid course for Java , Spring Boot and Microservices . I need to buy.
Teaching a Toddler Household Habits: Diaper Disposal & Potty Training #shorts
00:16
Modus males sekolah
00:14
fitrop
Рет қаралды 20 МЛН
Dad gives best memory keeper
01:00
Justin Flom
Рет қаралды 23 МЛН
Magic or …? 😱 reveal video on profile 🫢
00:14
Andrey Grechka
Рет қаралды 80 МЛН
CompletableFuture in Java 8 -  (Part 1)
23:35
Tech Recipes - Dipesh Hadye
Рет қаралды 20 М.
Java 8 Streams | Optional Usage and Best Practices | JavaTechie
22:22
Introduction to CompletableFuture in Java 8
19:34
Defog Tech
Рет қаралды 325 М.
Teaching a Toddler Household Habits: Diaper Disposal & Potty Training #shorts
00:16