Java Concurrency Interview: Implement Scatter Gather pattern

  Рет қаралды 42,898

Defog Tech

Defog Tech

Күн бұрын

Пікірлер: 67
@mattj65816
@mattj65816 5 жыл бұрын
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 KZbin. 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.
@8Trails50
@8Trails50 5 жыл бұрын
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 жыл бұрын
One of the excellent explanation(EE+) found in you tube. 100000+ incremental Likes...
@tusd100
@tusd100 3 жыл бұрын
One of the best content w.r.t multithreading in java
@jagannathsahu1087
@jagannathsahu1087 Жыл бұрын
Thanks. Everyone should go through these types of lessons to get more understandings on concurrency patterns
@SatyanarayanaBolenedi
@SatyanarayanaBolenedi 4 жыл бұрын
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"!!
@mohitdarmwal7309
@mohitdarmwal7309 5 жыл бұрын
one of the best content and work on concurrency, Keep the Good Work and a very thanks for the information :-)
@anubhavkumar2246
@anubhavkumar2246 5 жыл бұрын
These videos helped a lot in starting my job as SDE-1. I am truly indebted to this channel.
@theunusual4566
@theunusual4566 11 ай бұрын
for m=1 to infinity Thanking you for Explaining the concepts so Amazingly
@pdteach
@pdteach 2 жыл бұрын
Covers quite a topic in one go. Thanks
@ShivSinghSengar7013
@ShivSinghSengar7013 3 жыл бұрын
Gr8 way of explanation better if I had visited here than reading concurrency in practice first
@ILuvBilli
@ILuvBilli 5 жыл бұрын
I have seen CoundownLatch many times but first time understand since your way explanation is too good
@shrikantarbat2506
@shrikantarbat2506 5 жыл бұрын
How someone cn dare to dislike such informative videos...:(
@spinningbullet9136
@spinningbullet9136 4 жыл бұрын
I use this for timeout invokeAll(Collection
@quantum634
@quantum634 5 жыл бұрын
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.
@freemeplzplz
@freemeplzplz 5 жыл бұрын
Your videos on concurrency are really amazing. Please keep adding them.
@MadhuCM
@MadhuCM 5 жыл бұрын
Brilliant. Thanks for giving this wonderful session and I really appreciate that you are spending your time that benefit others.
@satyanarayanajammala5129
@satyanarayanajammala5129 5 жыл бұрын
You're awesome boss. The best explanation I have ever seen in KZbin
@ragingpahadi
@ragingpahadi 4 жыл бұрын
Love your videos ! Please keep them running
@Sambitsabyasachi00
@Sambitsabyasachi00 5 жыл бұрын
Thanks for making wonderful videos and plz make some videos on Spring security and Oauth2.
@LawZist
@LawZist 4 жыл бұрын
I will be more then happy to see new videos from you :)
@ShrinathKuppa
@ShrinathKuppa 3 жыл бұрын
Thank you for this video. Really helps understand the concept better!
@ruhirc
@ruhirc 4 жыл бұрын
good explanation, it will be great to see exception handling too.
@AbhishekVaid
@AbhishekVaid 2 жыл бұрын
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.
@matthewsaucedo2471
@matthewsaucedo2471 9 ай бұрын
This is an excellent point!
@dineshchandgr
@dineshchandgr 4 жыл бұрын
Amazing Video. Great clarity and communication
@lukevin3833
@lukevin3833 5 жыл бұрын
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 5 жыл бұрын
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 4 жыл бұрын
@@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!!
@neerajsharma8876
@neerajsharma8876 5 жыл бұрын
Thanks for making wonderful videos on concurrency .please make some videos on concurrent collections and stamped lock.
@souravsarker9100
@souravsarker9100 5 жыл бұрын
Dude, awesome explanation. Really appreciate your effort for making these valuable videos.
@hreddy
@hreddy 3 жыл бұрын
Super video! I applauded for ₹40.00 👏
@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.
@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.
@jeremythen7239
@jeremythen7239 5 жыл бұрын
That was wonderful man. Keep it up. You are the best.
@IlyaTkachev-hs8cb
@IlyaTkachev-hs8cb 2 жыл бұрын
Thanks a lot for your tutorials!!!
@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 4 жыл бұрын
Awesome explanantion . Why are you using Set for prices? Cuzz prices can be same in that case we will not get all required result
@sharanyarai378
@sharanyarai378 5 жыл бұрын
Perfect ! I Your time and efforts greatly appreciated.
@ChrisAthanas
@ChrisAthanas 4 жыл бұрын
Excellent explanation
@mostinho7
@mostinho7 3 жыл бұрын
Done thanks took notes
@virendrashinde304
@virendrashinde304 3 жыл бұрын
awesome explanation.
@sambhudevware7262
@sambhudevware7262 4 жыл бұрын
Is there videos for concurrency collection such as concurrent HashMap implementation and internal working
@rohithvarma2311
@rohithvarma2311 5 жыл бұрын
Amazing videos....can you mqke videos on spring security ?
@javacodingskills5525
@javacodingskills5525 3 жыл бұрын
Great explanation bro :)
@anckursingh
@anckursingh 4 жыл бұрын
Workstealingpool could have been used? Or fork join pool explicitly?
@jakubcichy5220
@jakubcichy5220 4 жыл бұрын
very good chanel grats!
@kailashpatel223
@kailashpatel223 5 жыл бұрын
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 жыл бұрын
That's interesting, let me think about it (how to implement it)
@varunbhardwaj2267
@varunbhardwaj2267 3 жыл бұрын
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
@Saurabhnaik
@Saurabhnaik 3 жыл бұрын
Thanks
@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
@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
@saurabharaiyer
@saurabharaiyer 3 жыл бұрын
Thanks!
@nithishreddy9056
@nithishreddy9056 5 жыл бұрын
Sir,i m very new to IT sector and from. Elsctrical background.. Please provide github link for accessing your code to my machine
@divyangshah99
@divyangshah99 5 жыл бұрын
Awesome
@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 жыл бұрын
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.
@karthikmucheli7930
@karthikmucheli7930 4 жыл бұрын
Why not use thread.join(); ?
@cihanisler6643
@cihanisler6643 5 жыл бұрын
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 жыл бұрын
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.
@karimiumar
@karimiumar Жыл бұрын
Thanks!
@DefogTech
@DefogTech Жыл бұрын
Thank you for the support!
Understanding how ForkJoinPool works
13:16
Defog Tech
Рет қаралды 123 М.
Semaphore in Java Concurrency
9:40
Defog Tech
Рет қаралды 111 М.
Amazing remote control#devil  #lilith #funny #shorts
00:30
Devil Lilith
Рет қаралды 16 МЛН
ТВОИ РОДИТЕЛИ И ЧЕЛОВЕК ПАУК 😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 5 МЛН
Motorbike Smashes Into Porsche! 😱
00:15
Caters Clips
Рет қаралды 23 МЛН
ThreadLocal in Java
10:59
Defog Tech
Рет қаралды 187 М.
Deadlocks vs Livelocks - Java Concurrency - Java Brains
13:35
Java Brains
Рет қаралды 37 М.
5 Design Patterns That Are ACTUALLY Used By Developers
9:27
Alex Hyett
Рет қаралды 303 М.
Introduction to CompletableFuture in Java 8
19:34
Defog Tech
Рет қаралды 329 М.
Java 8 Streams API
15:45
Defog Tech
Рет қаралды 155 М.
Concurrency Concepts in Java by Douglas Hawkins
44:22
Devoxx Poland
Рет қаралды 50 М.
Phaser vs CountDownLatch vs CyclicBarrier
13:40
Defog Tech
Рет қаралды 77 М.
What are Java interrupts?
11:19
Defog Tech
Рет қаралды 57 М.
Amazing remote control#devil  #lilith #funny #shorts
00:30
Devil Lilith
Рет қаралды 16 МЛН