Producer Consumer Pattern - With Java Example

preview_player
Показать описание
The Producer Consumer Pattern is a work load distribution pattern where the number of worker threads is decoupled from the number of tasks they have to execute. In this video I explain how the producer consumer pattern works in multithreading. You can also implement the producer consumer pattern with processes (instead of threads), but since this video is part of a playlist about Java Concurrency, I will focus on how the producer consumer pattern looks for threads.

Chapters:
0:00 Producer consumer pattern introduction
4:01 Producer consumer pattern use cases
4:24 Reduce foreground thread latency - GUI app
7:21 Reduce foreground thread latency - server
9:50 Load balance between worker threads - recap
10:40 Backpressure management
13:50 Producer consumer Java code example

The Producer Consumer Pattern - text:

Java BlockingQueue - text / video:

Java Concurrency - text / video playlist:
Рекомендации по теме
Комментарии
Автор

Gets used everywhere in the industry .. such a simple concept yet an indispensable one. Thanks for picking it up

AD
Автор

Thanks Jakob for this video that just made these complex concepts so much easier for us to understand

singhvertika
Автор

Thanks a ton Jakon for such a useful and awesome series! You are such a awesome teacher.

contactdi
Автор

Thank you Jacob. This series about Threads well explained.

seydaozdemir
Автор

Thank you so much. I've been learning a lot from you.

jakhongirrasulov
Автор

This is awesome Jenkov . God bless you!!

vilastadoori
Автор

Good video with detailed explanation, keep up the work jakob

vikassharma
Автор

Backpressure is a misnomer as with so many terms in tech. (Take reverse proxy for example). Thanks to u, Back End Pressure is the correct term actually.

bartdart
Автор

Hello, I was wondering why the consumer threads are alternating? What makes them follow that behaviour? Thank you!

alexandrufilipescu
Автор

How would one retrieve and merge the results of the consumers once finished? Let's say a user (could be many users) clicks a button and produces many tasks to do like query a website and retrieve information that needs to be merged/summed up when all tasks for that user have been consumed. I am currently testing a multi user & threading environment with a custom thread pool, but this thread pool is working in a 'first come first serve' manner that is not very performant to say the least and I thought to give the consumer producer pattern a try, but I do not know if this is the correct approach. Would highly appreciate some advice from your side.

sectorseven
Автор

Jakob the videos are brilliant, I have a question as I was trying to tackle this on my own...say we have 3 threads (0, 1, 2) and we want thread 0 to msg all threads (1 and 2) and then we have thread 1 doing the same with threads 0 and 2...and so forth, how do we go about that? I know its kind of similar to the producer/consumer example but in this case each thread can produce/consume messages as they arrive? curious to know as I have found few resources on Stack as well as here :/

quantum
Автор

Is blockingQueue thread safe or synchronized or safe to use without volatile or locking mechanism ?

nirmalgurjar
Автор

Thanks Jacob for the video. I have a question, if we want to consume messages in the order they were produced using two consumers, how could we do that

rinkutekchandani
Автор

Can you please add more videos from basic to advanced level?

quangtuan
Автор

Thanks, great videos. apologies for clicking on dislike accidentally instead of like, don't know how to revert.

bbcable