Java Concurrency Interview: Implement Scatter Gather pattern

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 ก.พ. 2025

ความคิดเห็น • 68

  • @mattj65816
    @mattj65816 6 ปีที่แล้ว +47

    Please keep making these videos forever. They are wonderful for sending to junior developers who haven’t learned these things yet. You must have the most comprehensively “correct” fundamental Java tutorials on TH-cam. Case in point, your use of a synchronized set and a countdown latch here. They are not core to what you are teaching, but you use them anyway. I think most Java demos would use a HashSet and an int there, and it would likely work in a synthetic demo environment, but would yield insidious bugs in real life concurrent use. Thank you for your efforts.

  • @hreddy
    @hreddy 3 ปีที่แล้ว

    Super video! I applauded for ₹40.00 👏

  • @8Trails50
    @8Trails50 5 ปีที่แล้ว +2

    Man. These videos are just wonderful. I’m a junior developer who has desperately been trying to get better at concurrency and distributed systems. There really is a select few people breaking things down like this. Perfect mix of theory and practical knowledge. Thank you!

  • @SushilKumarBhaskar
    @SushilKumarBhaskar 5 ปีที่แล้ว +2

    One of the excellent explanation(EE+) found in you tube. 100000+ incremental Likes...

  • @mohitdarmwal7309
    @mohitdarmwal7309 5 ปีที่แล้ว +5

    one of the best content and work on concurrency, Keep the Good Work and a very thanks for the information :-)

  • @SatyanarayanaBolenedi
    @SatyanarayanaBolenedi 5 ปีที่แล้ว +2

    Wow... Man, I'm in love with your concurrency playlist!!
    Your explanations are so crisp & clear. Thanks a ton for making these videos!!
    I feel like giving a different title "Conquer the Concurrency in JAVA"!!

  • @saurabharaiyer
    @saurabharaiyer 3 ปีที่แล้ว

    Thanks!

  • @jagannathsahu1087
    @jagannathsahu1087 ปีที่แล้ว

    Thanks. Everyone should go through these types of lessons to get more understandings on concurrency patterns

  • @anubhavkumar2246
    @anubhavkumar2246 5 ปีที่แล้ว

    These videos helped a lot in starting my job as SDE-1. I am truly indebted to this channel.

  • @tusd100
    @tusd100 3 ปีที่แล้ว

    One of the best content w.r.t multithreading in java

  • @pdteach
    @pdteach 2 ปีที่แล้ว

    Covers quite a topic in one go. Thanks

  • @ILuvBilli
    @ILuvBilli 5 ปีที่แล้ว

    I have seen CoundownLatch many times but first time understand since your way explanation is too good

  • @LawZist
    @LawZist 4 ปีที่แล้ว

    I will be more then happy to see new videos from you :)

  • @shrikantarbat2506
    @shrikantarbat2506 5 ปีที่แล้ว

    How someone cn dare to dislike such informative videos...:(

  • @ShivSinghSengar7013
    @ShivSinghSengar7013 3 ปีที่แล้ว

    Gr8 way of explanation better if I had visited here than reading concurrency in practice first

  • @satyanarayanajammala5129
    @satyanarayanajammala5129 5 ปีที่แล้ว

    You're awesome boss. The best explanation I have ever seen in TH-cam

  • @ragingpahadi
    @ragingpahadi 4 ปีที่แล้ว

    Love your videos ! Please keep them running

  • @MadhuCM
    @MadhuCM 6 ปีที่แล้ว +1

    Brilliant. Thanks for giving this wonderful session and I really appreciate that you are spending your time that benefit others.

  • @freemeplzplz
    @freemeplzplz 6 ปีที่แล้ว

    Your videos on concurrency are really amazing. Please keep adding them.

  • @theunusual4566
    @theunusual4566 ปีที่แล้ว

    for m=1 to infinity
    Thanking you for Explaining the concepts so Amazingly

  • @riderprovider6213
    @riderprovider6213 2 หลายเดือนก่อน

    Another gem.

  • @ShrinathKuppa
    @ShrinathKuppa 3 ปีที่แล้ว

    Thank you for this video. Really helps understand the concept better!

  • @AbhishekVaid
    @AbhishekVaid 2 ปีที่แล้ว +1

    I think passing accumulator (although ThreadSafe) has a problem here. My thought process is that after 3 seconds, we are returning prices from main method. But the reference of this method is still with a running thread which might add another entry to the prices after the return statement. For me, this volatility might cause problems. A safe way would be to make a copy of the accumulator and return that value.

  • @quantum634
    @quantum634 6 ปีที่แล้ว

    From the beginning I knew you could solve this using CompleteabkeFuture's with .allOf, but after seeing the 2nd solution with CountdownLatch I find this more "elegant" and cleaner.
    Loving your videos. Keep up with the great work. Devs like me, can learn a lot of these type of tutorials. Thank you for putting so much work into it.

  • @jeremythen7239
    @jeremythen7239 6 ปีที่แล้ว

    That was wonderful man. Keep it up. You are the best.

  • @dineshchandgr
    @dineshchandgr 4 ปีที่แล้ว

    Amazing Video. Great clarity and communication

  • @Sambitsabyasachi00
    @Sambitsabyasachi00 6 ปีที่แล้ว +2

    Thanks for making wonderful videos and plz make some videos on Spring security and Oauth2.

  • @souravsarker9100
    @souravsarker9100 5 ปีที่แล้ว

    Dude, awesome explanation. Really appreciate your effort for making these valuable videos.

  • @spinningbullet9136
    @spinningbullet9136 5 ปีที่แล้ว

    I use this for timeout
    invokeAll(Collection

  • @IlyaTkachev-hs8cb
    @IlyaTkachev-hs8cb 2 ปีที่แล้ว

    Thanks a lot for your tutorials!!!

  • @lukevin3833
    @lukevin3833 6 ปีที่แล้ว +1

    Thanks, that's a good video! But I think there's a problem in code at 7:00
    Let's say there is one I/O thread cost 3. 1 second.
    The "business thread" executed code "latch.await(3, TimeUnit.SECONDS)", and execute other code over one second (but not finish yet), then the "invalid data" will still be settled into the set.
    So, I think we'd timing 3S in every I/O thread too.
    ps : I'm not good at English, sorry about that

    • @DefogTech
      @DefogTech  6 ปีที่แล้ว +1

      I think only problem is we are returning same set object which is still accessable by tasks. So we should instead return a copy of the set. Also, using a simple set used by multiple threads is not best. We should use some synchronized collection instead

    • @SatyanarayanaBolenedi
      @SatyanarayanaBolenedi 5 ปีที่แล้ว

      @@DefogTech Hey, I see just one price in output [0]. Not sure, why Task.prices is copying/appending old prices?? I've some doubts around how do share data structures across threads like this.
      Highly appreciate, if you can shed some light here...!!
      Thanks in advance!!

  • @ruhirc
    @ruhirc 4 ปีที่แล้ว

    good explanation, it will be great to see exception handling too.

  • @ChrisAthanas
    @ChrisAthanas 4 ปีที่แล้ว

    Excellent explanation

  • @javacodingskills5525
    @javacodingskills5525 3 ปีที่แล้ว

    Great explanation bro :)

  • @sharanyarai378
    @sharanyarai378 6 ปีที่แล้ว

    Perfect ! I Your time and efforts greatly appreciated.

  • @neerajbhatia2008
    @neerajbhatia2008 4 ปีที่แล้ว

    Awesome explanation and great presentation in all the videos, keep up the good work. I am subscribing to your channel now, I think CountAndLatch example impl might change if there are like more than 500 websites to gather price from and some of the threads have not yet started their work like change into runnable state so may be we need three latch in that scenario one for ready, one from main latch when all threads are ready and third one for completing the run(gathering all the prices) then await for completing latch.

  • @virendrashinde304
    @virendrashinde304 3 ปีที่แล้ว

    awesome explanation.

  • @neerajsharma8876
    @neerajsharma8876 6 ปีที่แล้ว

    Thanks for making wonderful videos on concurrency .please make some videos on concurrent collections and stamped lock.

  • @mostinho7
    @mostinho7 3 ปีที่แล้ว +1

    Done thanks took notes

  • @96cichy
    @96cichy 4 ปีที่แล้ว

    very good chanel grats!

  • @sadanandburud5157
    @sadanandburud5157 4 ปีที่แล้ว

    Incredible explanations you provide in all your videos. I really amazed by your explanation. And one best positive thing is, you make it easy and for others it's easy to grasp and which stores the concept in the permanent memory. :).
    I have one question related to this video...... If thread doesn't perform the task in that particular time period which was set in await or any other method, what happens to that thread, will it get killed or do we need to send the interrupt signal..? Or will it get killed by itself.. if doesn't kill, and if consider it's doing some memory processing logic as well. Then havoc situation will arrive. Could you please reply what exactly happens..

  • @gautammishra3436
    @gautammishra3436 5 ปีที่แล้ว

    Awesome explanantion .
    Why are you using Set for prices?
    Cuzz prices can be same in that case we will not get all required result

  • @varunbhardwaj2267
    @varunbhardwaj2267 4 ปีที่แล้ว

    For scatter gather pattern can we try with for ExecutorService invokeAll() api because it will also return collection of futures and will retrieving using get() method we could timeout

  • @originaladmin
    @originaladmin 4 ปีที่แล้ว

    Great vid. Although one doubt, this can be done using ScheduledExecutorService also, right?

    • @DefogTech
      @DefogTech  4 ปีที่แล้ว

      Yes, but still need synchronization/logic to understand when all tasks are done for each request

  • @sambhudevware7262
    @sambhudevware7262 4 ปีที่แล้ว

    Is there videos for concurrency collection such as concurrent HashMap implementation and internal working

  • @anckursingh
    @anckursingh 4 ปีที่แล้ว

    Workstealingpool could have been used? Or fork join pool explicitly?

  • @Saurabhnaik
    @Saurabhnaik 3 ปีที่แล้ว

    Thanks

  • @kailashpatel223
    @kailashpatel223 5 ปีที่แล้ว +1

    A big fan of your work..
    I have a problem statement:
    We read from a big file and write data in batches into database. If one of the batch fail then whole file should fail.
    Could you make a video on how this can be achieved?
    If i have to write it then all I could think of is to add a method to delete currennt file's records in exception block.
    May be this is a silly question but any response will be appreciated.

    • @DefogTech
      @DefogTech  5 ปีที่แล้ว +1

      That's interesting, let me think about it (how to implement it)

  • @cihanisler6643
    @cihanisler6643 5 ปีที่แล้ว +1

    This doesn't look quite efficient to me. What if there are 50 websites you need to visit ? Are you going to create 50 threads ? This is a web app as you specified and main thread is blocking up to 3 sec while waiting for other threads to complete their tasks, what if you get 100 requests at the same time ? Throughput will be very low and app will not respond. Also in terms of Cpu and memory usage creating one thread per website will not be efficient. I think the efficient solution is to use reactor java (non-blocking io) and event-loop architecture instead of thread-per request model for this kind of problem, especially if this is web app.

    • @DefogTech
      @DefogTech  5 ปีที่แล้ว +6

      You are right, if the use-case changes where 50 sites are to be hit and request throughput is high then either Reactive IO or a light-weight threads like Fibers (I have created videos for both of these topics) is more optimal.
      This video though is focussed on interview setting to understand candidate's knowledge about basic concurrency tools.

  • @ashishpatil8066
    @ashishpatil8066 5 ปีที่แล้ว

    Nice video.. 1 query--> What if 2 threads completed and control returned to main method , but still thread-2 will keep on executing?

    • @DefogTech
      @DefogTech  5 ปีที่แล้ว +1

      Yes, if there is a timeout.. the threads will not know the main thread has moved on.. they will execute and complete their tasks, buy by that time main thread has moved on

    • @ashishpatil8066
      @ashishpatil8066 5 ปีที่แล้ว

      @@DefogTech ok.. Thanks.

  • @muesligangster
    @muesligangster 3 ปีที่แล้ว

    wouldn't it be more efficient to use an event approach hier to fetch all the data?
    The computing time isn't that much and the overhead for threads could be much more than with an non blocken I/O such as NIO for example. And it would be much easier for scaling

  • @divyangshah99
    @divyangshah99 5 ปีที่แล้ว

    Awesome

  • @rohithvarma2311
    @rohithvarma2311 6 ปีที่แล้ว

    Amazing videos....can you mqke videos on spring security ?

  • @nithishreddy9056
    @nithishreddy9056 6 ปีที่แล้ว

    Sir,i m very new to IT sector and from. Elsctrical background.. Please provide github link for accessing your code to my machine

  • @karthikmucheli7930
    @karthikmucheli7930 5 ปีที่แล้ว

    Why not use thread.join(); ?

  • @madnorbi
    @madnorbi 3 ปีที่แล้ว

    Excellent!
    Small note: it might make sense to also handle the possible TimeoutException.
    Say "allTasks.get(3, TimeUnit.SECONDS)" times out.
    In this case the intended action is to still return a partial result instead of propagating the TimeoutException.

  • @karimiumar
    @karimiumar 2 ปีที่แล้ว

    Thanks!

    • @DefogTech
      @DefogTech  2 ปีที่แล้ว

      Thank you for the support!