Java Concurrency Interview: Implement Producer Consumer pattern using wait-notify

preview_player
Показать описание
Implementing Producer Consumer using BlockingQueue, Locks/Conditions and Wait-Notify.

Important: The last part about using wait-notify is incorrect. My mistake, sorry about that.

The object used to wait/notify should be the same object used by threads to synchronize (to avoid IllegalMonitorStateException). So correct code should be similar to:

synchronize(sharedQ){
sharedQ.wait();
}
synchronize(sharedQ){
sharedQ.notifyAll();
}

That was a basic mistake which I should have caught. I feel bad about misleading the initial viewers. Sorry.

Channel
----------------------------------
Master difficult programming concepts in few minutes. I try to explain difficult concepts like Java concurrency in simple to understand manner. Explore videos on topics like Spring Boot, Cloud Foundry, Java 8 and more. I am happy to clarify your doubts. Ask me anything in the comments. Also happy to take requests for new videos.

New video added every Sunday.

Current Playlists
----------------------------------

Popular Videos
----------------------------------
Рекомендации по теме
Комментарии
Автор

Important: The last part about using wait-notify is incorrect. My mistake, sorry about that.

The object used to wait/notify should be the same object used by threads to synchronize. So correct code should be similar to:

synchronize(sharedQ){
sharedQ.wait();
}
synchronize(sharedQ){
sharedQ.notifyAll();
}

That was a basic mistake which I should have caught. I feel bad about misleading the initial viewers. Sorry.

DefogTech
Автор

Even years later, thank you for this video, it 's very useful and helped me finally understand this topic... sincere thanks

EduardoAndersonRivasSalas
Автор

I generally don't put a comment for any video until I really like them. I must say that u explain each and everything very clearly. I don't have hands-on experience on multithreading and concurrency but with your videos, I find myself so comfortable with all these ..Keep uploading .after a long time I liked something good on youtube :)

shradhabharti
Автор

Thank you for making this video, I watched it some few years back and I still came back to re-watch it in 2024. Thanks a lot for such a great teaching.

mustapharaimilawal
Автор

This channel teaches more about the approach to solving the problem.They don't go to the solution straight away, first they come to common implemented pattern, than they optimize the solution.
Brilliant

kunalbudhiraja
Автор

first time learning about producer-consumer. your explanation is very clear and easy to understand

radhianand
Автор

this is the only channel that make me realize multithreading can be learnt thanks a lot man keep making more of such gems 😀

RohitBagdi-bvno
Автор

GENIUS !! No other words. Such a smooth and clear explanation to the problem

rohansinha
Автор

Hi @Defog Tech, This is the my first comment on youtube in last 5 years, Your videos are very helpful, I have really understood the Java concurrency on your channel. Please keep uploading such awesome content. Thanks

vishalsharma
Автор

Best clear explanation of a very complicated subject

ChrisAthanas
Автор

Greetings from Russia, having watched hours of content on concurrency/multithreading, this is the by far the best one i have seen, top notch.

СергейСергеев-щсй
Автор

your videos are crisp and clear! that's the way to talk about complex topics.. thank you so much man!

govindraokulkarni
Автор

I love your tutorials! I did this example myself and found a little but meaningful bug:
-notEmpty and notFull should be called ".signal()" instead of ".signalAll()" because in case of releasing one spot in the queue by take() method, if there are multiple "putting" Threads, they are all notified at once about free space and they add concurently its own item exceeding the maxSize (and later condition `queue.size() == max` doesn't catch situation when this size is exceeded)

arek
Автор

this video has cleared a lot of my doubts and the way you have explained will help me remembering it for a very very long time ! Thanks for your hard and crisp work !

aatifnazar
Автор

Easy explanation of any topic. I really like your way of explaining any topic.

abadheshkrjha
Автор

8:50 instead of checking if queue.size==0 and then waiting on the condition, we must check that in a while loop because after resuming from the condition, another thread could have resumed before us, and the queue.size that we checked before would be outdated (the other thread that resumed before us took what was in the queue already)

mostinho
Автор

Hi, I have one doubt.
At 8:52
How can two threads simulatenaosly access the code put after acquiring the lock?
Am I missing anything?

shahrozsaleem
Автор

Best videos of all time and even youtube understood that and suggesting on top of everyone

sharatchandra
Автор

This channel always have unique topics and content.

diwakar.singh_official
Автор

BEAUTIFUL! Spoken way better than my professor

Bagunka