Multi-Threading in Spring Boot using CompletableFuture | @Async | JavaTechie

Ғылым және технология

This video will guide you How to perform Multi-Threading in Spring Boot Using CompletableFuture also you will learn about Thread-pool Execution
#javatechie #CompletableFuture #SpringBoot #MultiThreading
GitHub:
github.com/Java-Techie-jt/spr...
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

Пікірлер: 206

  • @lidwinx
    @lidwinx3 жыл бұрын

    Basant, thanks for the video, well done, you always rock..!! Keep posting !!!

  • @umareddy2902
    @umareddy29024 жыл бұрын

    I have implemented successfully and understood the concept very well plz keep posting videos like this.. Thank a lot for the videos on latest technologies.

  • @shreem6447
    @shreem64472 жыл бұрын

    Well done explaining rare and tough topics using easy hands-on

  • @maheswaran.s
    @maheswaran.s3 жыл бұрын

    I'm impressed with the way you explain. It is very clear, thank you!!👍

  • @jayjoshi1366
    @jayjoshi1366 Жыл бұрын

    This is the best video and explanation I have found to implement MultiThreading using SpringBoot and REST APIs. I am learning Spring Boot and trying to implement Multi threading in it. Thanks for the video. Please make more video on it using a complex scenario and complex API end points, maybe with 10 threads or more. Thanks @javatechie :)

  • @avijitsharma5050
    @avijitsharma50504 жыл бұрын

    5:33 - configuration bean for executor/ThreadpoolTaskExecutor 10:24 - parseCSVFile() [which contains try with resource] 13:14 - @Async , CompletableFuture.completedFuture(users); 22:41 - three threads for fetching data from H2 console 24:04 - join the result of three tasks using CompletableFuture.allOf(), join() method

  • @codingshiv1670

    @codingshiv1670

    2 жыл бұрын

    Its really annoying why the Java Techie doesn't add timestamps

  • @Javatechie

    @Javatechie

    2 жыл бұрын

    Shiva my role is here to explain the concept .if you understand it correctly then it's good .

  • @codingshiv1670

    @codingshiv1670

    2 жыл бұрын

    @@Javatechie As a presenter imo u need to care about user experience. Timestamps really help in that area. Eventually its ur call. BTW nice content. Recently found this channel. It would be more helpful to browse through the content more fluidly via timestamps of contents. Thanks for reply

  • @Javatechie

    @Javatechie

    2 жыл бұрын

    @@codingshiv1670 I completely agree with you. Going forward I will take care this for longer video

  • @SaurabhKumar-rr1vi
    @SaurabhKumar-rr1vi Жыл бұрын

    wow , such a simple explanation . Thank you.

  • @shamsherali7284
    @shamsherali72843 жыл бұрын

    Man U rock .thanks for this valuable lecture

  • @jean-baptistedioli1692
    @jean-baptistedioli16924 жыл бұрын

    Thanks for the video. I'm beginner and it's a little bit difficult to understand everything correctly. Is it possible to make a video to explain the "philosophy" by a schema ? with code example ?

  • @nelsonraulbrizuela79
    @nelsonraulbrizuela79 Жыл бұрын

    you are very good at explaining my friend, thank you very much for the video

  • @Igor-uz3vn
    @Igor-uz3vn3 жыл бұрын

    Thanks for great tutorial!

  • @sriaya1743
    @sriaya17434 жыл бұрын

    Nice video sir, hopefully you will extend this further for exception handling in completable future, running each tasks separately / stop running the tasks intermittently etc. Thanks

  • @Javatechie

    @Javatechie

    4 жыл бұрын

    Hi Sri , yes will do that 👍

  • @gopisambasivarao5282
    @gopisambasivarao52829 ай бұрын

    Appreciate your efforts Basant. God Bless you..🙂

  • @sathiskumarp
    @sathiskumarp Жыл бұрын

    Thank you so much. It's really awesome

  • @UmeshKumar-pq3kc
    @UmeshKumar-pq3kc3 жыл бұрын

    Thank you so much for a wonderful example, I am going to use this today itself in of the big project of leading bank in the world.

  • @abhishekdubey5336
    @abhishekdubey53363 жыл бұрын

    Very Nice and quick hands on explanation for Multi threading, it would be great if you can explain a bit on how and why we need to create Executors and how Completable Future helps, to make the theory clear

  • @pradeepvirtuele7160

    @pradeepvirtuele7160

    2 жыл бұрын

    Yes I agreed @Abhishek Dubey It would be great if this explain in debugging mode

  • @bhaktilatadash7619
    @bhaktilatadash76193 жыл бұрын

    Thank u Brother for ur efforts....

  • @sandeep_begudem
    @sandeep_begudem9 ай бұрын

    @Javatechie Thank you so much for the tutorial. I enjoyed learning it. Could you do a tutorial on rest of the methods that are available in CompletableFuture?

  • @MirekKrenc
    @MirekKrenc2 жыл бұрын

    Great, thank you.

  • @sreenivasl221
    @sreenivasl2212 жыл бұрын

    Thanks.. Teaching is very understandable...

  • @sivakumarreddivari686
    @sivakumarreddivari6862 жыл бұрын

    thanks for the crystal clear explanation. How to make it conditional. like for example I want to modify first 10 records in csv file to new emails and other thread should not process those 10 records until the first one is done ?

  • @krishnasuripaka2480
    @krishnasuripaka24803 жыл бұрын

    Super tutorial..u r always super...

  • @Bahmed825
    @Bahmed8252 жыл бұрын

    Very good tutorial.

  • @thebachelorpad1110
    @thebachelorpad11103 жыл бұрын

    Jabardast! I am your fan buddy! keep doing good stuff!

  • @josheluis6610
    @josheluis66103 жыл бұрын

    Maravilloso :3 me salvaste like y subscribir Saludos de Ecuador

  • @psudhakarreddy6548
    @psudhakarreddy654828 күн бұрын

    Thank you 🙏

  • @mayanksen3061
    @mayanksen30614 жыл бұрын

    Thankyou sir...

  • @pratyusharajanala3750
    @pratyusharajanala37502 жыл бұрын

    Thanks for the detailed explanation. I have a doubt here .Is saveUsers method which calls praseCSV method uses multi threading? If Yes , how it splits to read the data if we have only one Input CSV.

  • @duzgunkenan
    @duzgunkenan Жыл бұрын

    I smile everytime you say "Isn't it?" :D

  • @Javatechie

    @Javatechie

    Жыл бұрын

    Why don’t you like it 😂

  • @duzgunkenan

    @duzgunkenan

    Жыл бұрын

    @@Javatechie No, on the contrary, I like it :)

  • @arpit-jain
    @arpit-jain Жыл бұрын

    Really appreciate your work. I have a question here, what if we want consolidated response of all Async call done inside a for loop instead of returning just Responseentity at 17:30. How to do that? And do these threads created by Spring stop automatically?

  • @compartelo007
    @compartelo0074 жыл бұрын

    Great example, thanks

  • @compartelo007

    @compartelo007

    4 жыл бұрын

    I understand little in English but you speak slowly and then for me it was much easier, thanks

  • @chinnarajr8689
    @chinnarajr86892 жыл бұрын

    Very good video, Could you please post a new video for handle the exception in completable Future(For example- There are two futures future1 and future2, then future1 is executed successfully and future2 is throwing exception but I want the result from future1 and send back to client). This is one of the interview question which I faced recently? Thank you

  • @aviksutar6694
    @aviksutar669411 ай бұрын

    lovely

  • @vinodnayak27
    @vinodnayak27 Жыл бұрын

    Hi Basant, I recently started to fallow your channel and loveedd the way to deliver the content😍. Can you please make a playlist on multi-threading and thread pools mapping with real time senarios in your style😎.

  • @Javatechie

    @Javatechie

    Жыл бұрын

    Thanks vinod ☺️. Noted your suggestion

  • @vinodnayak27

    @vinodnayak27

    Жыл бұрын

    @@Javatechie thanks❤

  • @manasipalkar9794
    @manasipalkar9794 Жыл бұрын

    this is amazing

  • @manichhina3984
    @manichhina3984 Жыл бұрын

    very good explained !!!

  • @Iyauricastillo
    @Iyauricastillo4 жыл бұрын

    Thank you for your video. I have a question please: Is this an alternative to DeferredResult method or maybe this is a better approach to handle async requests?

  • @Javatechie

    @Javatechie

    4 жыл бұрын

    Am not aware about this DeferredResult method

  • @FaheemIlahi
    @FaheemIlahi2 жыл бұрын

    I don't know why you have less subscribers. You are awesome

  • @Javatechie

    @Javatechie

    2 жыл бұрын

    Thanks buddy 😊

  • @nagarajumuddey465
    @nagarajumuddey465 Жыл бұрын

    nice

  • @hakkisan2508
    @hakkisan25083 жыл бұрын

    Don't understand the dislikes. He gives us lot of infos for some people to much for others to obviously. But other than you he gives us a lot of good information. You give us just zero Input only useless data on youtube server 😝

  • @sureshsadanala4639
    @sureshsadanala46392 жыл бұрын

    Basant bro, very good one 👍

  • @ssshanmugam4514
    @ssshanmugam45143 жыл бұрын

    Please make a video regarding implementing dynamic search query using spring data JPA and pdf and excel generation

  • @balaveeraraghavareddy9764
    @balaveeraraghavareddy97644 жыл бұрын

    Very nice tutorial could you please make a video on how to write pojo to CSV in spring boot without using open csv

  • @amanueltesfu6071
    @amanueltesfu60712 жыл бұрын

    You are fabulous. Thanks my friend!

  • @SohailKhan-gu2du
    @SohailKhan-gu2du2 жыл бұрын

    Hey man.... U r very knowledgeable.. Can u create some. Complex apps... Using spring boot.. Kafka.. Multi threading n all.... Like handling huge traffics of request... Apart from this simple crud apps

  • @seatconnect224
    @seatconnect2242 жыл бұрын

    it also will be good if you do some video about concurrency in Java with describing deadlocks and so on

  • @johncerpa3782
    @johncerpa37823 жыл бұрын

    Good video!

  • @sinurao1017
    @sinurao10173 жыл бұрын

    Hi JT, Small suggestion add subtitles to your videos incase if we miss any terminology

  • @JERILNADAR
    @JERILNADAR4 жыл бұрын

    In the getUsersbyThread how do we return the list of users as response once all the all threads have completed their work and we join them.

  • @aayushkc2306
    @aayushkc23064 жыл бұрын

    how can i make a real time push notification in java web app ?? can you make the video series on long-polling and short polling features?

  • @JavaWallah-tp3ue
    @JavaWallah-tp3ue4 жыл бұрын

    please make full video on spring auth2 security with jwt token

  • @AmritAgarwal07
    @AmritAgarwal07 Жыл бұрын

    Most interviews asked questions on the Executor framework. of thread Can you make a video on that?

  • @vickeychoudhary7399
    @vickeychoudhary73994 жыл бұрын

    thanks basant kumar sir

  • @indomie6384
    @indomie63844 жыл бұрын

    Hello sir, could you please show us how to add other methods like PUT, DELETE, and get by ID?

  • @AbhimanyuKumar-xe5dq
    @AbhimanyuKumar-xe5dq3 жыл бұрын

    Hi basant we can use supplyAsync() also so why we need @Async annotation any benefit.

  • @ahmedahmed-my1iq
    @ahmedahmed-my1iq5 ай бұрын

    Hi Basant- can you tell us how does the thread knows how to split the work between them when you have not indicated this in your code? wont there be overlapping in performing the task? I see using single thread is as fast or faster than multiple threads.

  • @mjagan619
    @mjagan6192 жыл бұрын

    Thanks for the knowledge sharing. What type of thread pool you have created in the video?

  • @Javatechie

    @Javatechie

    2 жыл бұрын

    Custom thread pool

  • @yuvarajs3510
    @yuvarajs35102 жыл бұрын

    In getUsers API, you are calling the same services three times by two different threads, but findAllUsers method in service class will return the same data for each call. How is it consolidating the final data from three calls by different threads?

  • @avinashverma7141

    @avinashverma7141

    Жыл бұрын

    I think the wait() method can distinguish the thread call.

  • @dmitrikonnov922
    @dmitrikonnov922 Жыл бұрын

    I'm just having hard time telling difference between ThreadPoolTaskExecutor that we configure and thread pool executor of tomcat server that handles http requests. Are these the same pool?

  • @aman_bharti
    @aman_bharti3 жыл бұрын

    Can you please explain the advantage of using ThreadPoolTaskExecutor over SimpleAsyncTaskExecutor?

  • @krishnendughosh2368

    @krishnendughosh2368

    6 ай бұрын

    You get more control while using ThreadPoolExecutor.......like setting up core pool, max pool (understand these two) You get the queue feature. In the simple one it creates one thread for each task, no concept of queue. Threadpool is also resource friendly since it uses pool and dont just create a new thread for each new task. Also there is a bound mechanism which prevents it from creating infinite no of threads. You can set up the thread names too in threadpool...and manage the thread lie cycles in a much better way. You can use the Simple one if you are working on a personal or small project but in a company or for any big project you should use ThreadPoolExecutor

  • @artem1554
    @artem15542 жыл бұрын

    Thanks for a nice video! I've question regarding async method. Why in video for async method used CompletableFuture.completedFuture(users) and not CompletableFuture.supplyAsync(() -> users)?

  • @basketballfan4eva
    @basketballfan4eva4 жыл бұрын

    What is the benefit of returning a CompletableFuture in the REST Controller endpoint? I understand it frees up a tomcat thread, but in that case, why not just increase the number of tomcat threads?

  • @Javatechie

    @Javatechie

    4 жыл бұрын

    Hi , I believe Rather than increase thread count we can resuse them

  • @ayushdixit7605
    @ayushdixit76052 жыл бұрын

    Hello Sir, I'm able to fetch response in parallel manner. But when I'm applying @Async on saveUser method, I'm getting FileNotFoundExcetion: System can't find the path specified. On Removing @Async from method it's working. Could you please suggest any changes on above issue.

  • @souvikadhikary8990
    @souvikadhikary89903 жыл бұрын

    Good One! But now Spring has provided us Flux & Mono with Reactive Repository interfaces!!! Java's features are becoming obsolete !! :(

  • @Javatechie

    @Javatechie

    3 жыл бұрын

    Yes reactive programming is more popular now a days .I will start a brand new series with it .

  • @user-yw9us2qo6g
    @user-yw9us2qo6g4 жыл бұрын

    If something will go wrong in the saveUsers method the response in any case will be Created, right? Because as I see, since service.saveUsers is invoked in separate threadPool spring is returning the response without waiting the end of execution

  • @Javatechie

    @Javatechie

    4 жыл бұрын

    Yes exactly , even though there is any exception in any thread it won't stop your execution . But there is better solution to handle fault , will do that

  • @benpracht2655
    @benpracht26552 жыл бұрын

    If I had work that I wanted to split among many threads, not just call a method with a completable future, what would I need to do?

  • @adobongasin214
    @adobongasin214 Жыл бұрын

    But how can you use the Threads? in your example you have user1,user2,user3 and join them all but how can you return them as response with the results from the DB?

  • @xiuyeding5191
    @xiuyeding51914 ай бұрын

    a little confused when you use 3 threads fetching the data, will it improve the response time? I think each thread is independent and will fetch all the data from db, then why need to use 3 threads and join the result? pls correct me if I’m wrong.

  • @AnkitKumar-yw2ue
    @AnkitKumar-yw2ue3 жыл бұрын

    Liked this video. You demonstrated the thread pool concept well. But I think this is not a proper example of CompletableFuture

  • @Javatechie

    @Javatechie

    3 жыл бұрын

    Yes this is how we should use completableFuture

  • @CashLootsOfficial
    @CashLootsOfficial Жыл бұрын

    for using 2 threads itself i am getting output as list of users fetched by get is from thread 3 from where did thread 3 come into picture? i had specified the thread count as 2 only.

  • @sureshmanne7245
    @sureshmanne7245 Жыл бұрын

    I have seen your spring batch video also and so my confusion now where both of these videos (Spring Batch & CompletableFuture) are processing csv file to store and retrieve data. Which one is better approach to process the csv files and why?

  • @Javatechie

    @Javatechie

    Жыл бұрын

    One is the framework that automates the process that is a spring framework and ComplerableFuture is just a way to perform concurrent flow

  • @studyaccount5578
    @studyaccount5578 Жыл бұрын

    The GET call with single thread showed JSON User data, but after u converted it to Multithreading the same GET call did not return any results. I was interested to see how the results from each threads are stitched together and does the sequence of the data fetched changes

  • @Javatechie

    @Javatechie

    Жыл бұрын

    You need to join or combine all threads to get results

  • @kayeshparvez
    @kayeshparvez3 жыл бұрын

    What could I do if I wanted to return the saved names in return of the post request ?

  • @muchukundareddy5315
    @muchukundareddy53152 жыл бұрын

    Thank you so much. But I did not see any difference b/w implementing using the traditional approach and using a thread pool.

  • @Javatechie

    @Javatechie

    2 жыл бұрын

    Last get method was actual implementation of multi threading

  • @jayjoshi1366
    @jayjoshi1366 Жыл бұрын

    If I call different APIs like - getAllUsers(), getUsersById(), getUsersByName(), getUsersByEmail(), getUsersByGender(), and use CompletableFuture along with @Async Config class for ThreadPoolTaskExecutor; then only getAllUsers() is getting called by my custom created thread "userThread-1". But other APIs are called/executed by the Tomcat's threadpool executor http-nio-8080-exec-1. Can you please explain on this, that why other APIs are being executed by the Tomcat's nio executor and not our configured ThreadPoolTaskExecutor. It would be really appreciated as I am very much stuck into this. Thanks in advance _/\_

  • @sarathtj8264
    @sarathtj82643 жыл бұрын

    Even for posting the files are using multi threading concept

  • @shubhamkumar-bz2ps
    @shubhamkumar-bz2ps Жыл бұрын

    In this case will the ouput of the users will be in exact same sequence as it was stored in Db??

  • @Javatechie

    @Javatechie

    Жыл бұрын

    Yes

  • @smrutinayak2628
    @smrutinayak26284 жыл бұрын

    Hi Basant, i cloned the same project but am not able to upload the file , can you please help me

  • @i_am_kshitij1118
    @i_am_kshitij11183 ай бұрын

    How to integrate sleuth, as span I'd is not getting progatated to async method

  • @natetolbert3671
    @natetolbert36713 жыл бұрын

    Why the nested try block in UserService class? Why not just add the catch to the inner block and get rid of the outer? And why all these static methods? I am used to core Java ; it feels like Spring is throwing OOP out the window.

  • @ShinAkuma

    @ShinAkuma

    2 жыл бұрын

    I believe the outer try is meant for exception handling while inner try is just meant to avoid writing close() method for the buffered reader.

  • @dsa6030
    @dsa60304 жыл бұрын

    Hi..i have a question...say my backend is in spring boot and i apply this async for one of my calls...and set maxsize as 5...now only 5 threads will be there to get the tesk done...say 10 users login ...will the app method still be accessible to those 5 users?

  • @Javatechie

    @Javatechie

    4 жыл бұрын

    Once it serve 5 request , then who ever thread is free will go to task/request queue then will process further

  • @teguhep9444
    @teguhep94442 жыл бұрын

    hi, in the end your video, your endpoint getUsersByThread didn't return result, how to return the result?

  • @rajpradhan1807
    @rajpradhan18072 жыл бұрын

    How to get the response of getUsers(json) in postman?

  • @bluex217
    @bluex2172 ай бұрын

    What I don't understand is why all we need to do for saveUsers method is annotate with @Async but for findAllUsers methods with only @Async annotation still you showed it is not running multiple threads. What is the reason we need to explicitly create multiple CompleteableFuture object for findAllUsers but we don't need to do this for saveUser ?

  • @kayeshparvez
    @kayeshparvez3 жыл бұрын

    What would happen if you call the findAllUsers method 103 times. 2 will be running by two threads. the queue size is 100. so 100+2 = 102 tasks can be handled. What will happen to the 103rd task in this case ?

  • @Javatechie

    @Javatechie

    3 жыл бұрын

    Queue size meant to hold waiting task in queue Who ever thread serving 101 and 102 request once any one release he will pick 103 task in queue Note : queue will not always full with task , if task executed then it will release from queue and new task will add to queue in FIFO manner

  • @kayeshparvez

    @kayeshparvez

    3 жыл бұрын

    @@Javatechie got it now. thanks 😊

  • @somnathchaudhuri8698
    @somnathchaudhuri8698 Жыл бұрын

    How to stop the thread at the end of the execution, I am getting following error message "Appears to have started a thread name [Asynchread-2] but failed to stop it

  • @AdaptToFuture
    @AdaptToFutureАй бұрын

    Let's say we have two threads adding 1000 JSon objects to the database, what if they add 2000 objects. 1000 for each.?

  • @tejasnakhate
    @tejasnakhate Жыл бұрын

    I have one question, in controller when we called findAllUsers multiple times, each time it ran on a new thread. But when we call saveUsers multiple times in the for loop, it does not run in different thread even tough both saveUser and findAllUsers methods are annotated with @Async annotation in service. Why so?

  • @Javatechie

    @Javatechie

    Жыл бұрын

    Always recommend to use multi threading in read operation not in write operation

  • @tejasnakhate

    @tejasnakhate

    Жыл бұрын

    @@Javatechie but how does read operation does not go for multiple threads even tough it is annotated with async annotation?

  • @bluex217

    @bluex217

    2 ай бұрын

    @@tejasnakhateYes I not understand why we need to explicitly create several CompleableFuture objects when calling findAllUsers in order for multiple threads to be used but yet for saveUsers we do not need to and @Async annotation is enough for saveUsers but not for findAllUsers

  • @krupagayatri
    @krupagayatri2 жыл бұрын

    heyy. When i run the code, after hitting postmapping everything is okay. but after hitting getmapping, my rows are empty. please help

  • @Javatechie

    @Javatechie

    2 жыл бұрын

    Is data present in your database

  • @nayan.j
    @nayan.j2 жыл бұрын

    I am getting FutureTask can not be casted to CompletedFuture

  • @ritesisright
    @ritesisright3 жыл бұрын

    Nice... But you should have sumnerized code towards end... You doing too many things here...

  • @yogeshchaudhari9971
    @yogeshchaudhari99716 ай бұрын

    Nice video...one question...say i have 3 methods....method1 calling method2....method2 calling method3.....in method3 a rest api is called for some processing..... My question is do we need to annotate all three method1 method2 and method3 with @async annotation....i have this scenario in my project and trying to implement a solution for same.... If you can help please

  • @Javatechie

    @Javatechie

    6 ай бұрын

    No adding @Async in method 1 is absolutely fine but make sure all 3 method return types should be either void or Completablefuture

  • @yogeshchaudhari9971

    @yogeshchaudhari9971

    6 ай бұрын

    @@Javatechie ok thanks...i will try this.... thanks for all ur videos and knowledge sharing...i regularly watch ur videos and i appreciate ur efforts u put in knowledge sharing

  • @UmeshKumar-pq3kc
    @UmeshKumar-pq3kc3 жыл бұрын

    You joined three calls, how can we join N number of calls? Please explain. My requirement is to call service method for number of item available in list, then join to get final output. Any one pls comment

  • @ekeshkumar-rc4hb
    @ekeshkumar-rc4hb8 ай бұрын

    hi java techie

  • @shobharao3970
    @shobharao39703 жыл бұрын

    I tried this example today, when I get the users i get 500 internal server. I dont see the USER_TBL created in the H2 DB console. What else has to be done? appreciate it if you can answer.

  • @Javatechie

    @Javatechie

    3 жыл бұрын

    Did you configure Lombok in your IDE ?

  • @shobharao3970

    @shobharao3970

    3 жыл бұрын

    @@Javatechie I was able to figure out the issue. The problem was not with lombok, it was with H2 DB app properties. I did not configure it, so the DB connection was not made to create the table. But Thank you for replying as fast :)

  • @yogischannel9972
    @yogischannel99724 жыл бұрын

    sir canyou tell how to secured our rest api in using aouth or spring security tell better way please

  • @Javatechie

    @Javatechie

    4 жыл бұрын

    Already uploaded video please have a look once in spring boot playlist

  • @Shubham-bb6dr
    @Shubham-bb6dr10 ай бұрын

    i have one question ...in first method of async config class return type in excutor but returns ThreadPoolTaskExecutor...why?

  • @Javatechie

    @Javatechie

    10 ай бұрын

    Executor is an interface however ThreadPoolTaskExecutor is it's implementation

  • @Shubham-bb6dr

    @Shubham-bb6dr

    10 ай бұрын

    @@Javatechie it's my mistake actually I import executors which is class that's why I get error

  • @purbarunchakrabarti5564
    @purbarunchakrabarti55644 жыл бұрын

    Sir in the API, GET request of "/getUsersByThread" I am not getting the list of all users as a JSON response as in the API call "/users". Kindly help how to get a response of all users along with appropriate status.

  • @krupagayatri

    @krupagayatri

    2 жыл бұрын

    did you find any solution

  • @beeam1791
    @beeam17912 жыл бұрын

    Hello! I have one noob question, what is the purpose of using this? I've tried the same with sync call and got 353ms for request1 and 117ms for request2, while in async call it has 412ms for both calls

  • @ShinAkuma

    @ShinAkuma

    2 жыл бұрын

    This is an IO intensive task so time taken will be more or less the same no matter how many threads you create because records will still be inserted one by one only cause DB has to maintain consistent primary key IDs.

  • @beeam1791

    @beeam1791

    2 жыл бұрын

    @@ShinAkuma Sorry mate, but I didn't understand, could you please elaborate?

  • @bluex217

    @bluex217

    2 ай бұрын

    ​@@beeam1791I've got this 1 so basically what he means is, note that the database has an ID column in the User table, and the id column is the primary key. Primary keys must be UNIQUE, no 2 users can have the same primary key. So, imagine you have 10 threads each inserting some of the users from the list of users sent via the MultiPartFile like in this video, if thread-1 and thread-2 are running concurrently, thread-1 trying to insert a row into the users table for "John Doe", and thread-2 inserting for "Joe Smith", for example, but thread-1 sets John Doe's ID column to value of 1, and thread-2 sets Joe Smith's ID column also to 1, this cannot be, no 2 users can have the same ID. Therefore, the insertion of users must be done sequentially to ensure that no 2 users are inserted with the same ID. You'd likely get an exception if this happened, anyway, because ID columns are intrinsically unique.

  • @Elisha-Nyra-Rai
    @Elisha-Nyra-Rai2 жыл бұрын

    is this implemntation will work the millions of records?

  • @Javatechie

    @Javatechie

    2 жыл бұрын

    Yes why not

Келесі