Concurrency vs Parallelism

  Рет қаралды 63,074

Jakob Jenkov

Jakob Jenkov

Күн бұрын

Concurrency and Parallelism are two terms that are often used in relation to multithreaded or parallel programming. Concurrency and parallelism may seem to refer to the same or similar concepts on the surface. However, they are typically used to specify different types of multithreaded behaviour. In this Concurrency vs. Parallelism video I explain what the difference is.
Chapters:
0:00 Concurrency vs. Parallelism Introduction
0:26 Concurrency
2:03 Parallel Execution
3:01 Parallel Concurrent Execution
4:39 Parallelism
7:26 Combinations
Concurrency vs. Parallelism - Textual version:
tutorials.jenkov.com/java-conc...
Java Concurrency Tutorial - Text / Video:
tutorials.jenkov.com/java-conc...
• Java Concurrency and M...

Пікірлер: 136
@markojovanovic8444
@markojovanovic8444 3 жыл бұрын
Taking off your time to tech other and make it totally free, is a virtue to admire to. Thank you for your awesome tutorials and your time. :)
@JakobJenkov
@JakobJenkov 3 жыл бұрын
You are welcome! :-)
@ricardoarrobo9528
@ricardoarrobo9528 28 күн бұрын
I really liked the graphics on this, as a visual learner it makes it easier to follow.
@JakobJenkov
@JakobJenkov 18 күн бұрын
Great !! 😊
@shubhamagarwal1434
@shubhamagarwal1434 Ай бұрын
God of Concurency..i have bene flowing you since my 2014 when you used to write blog post only...by going through your post i attend interview like a LION when they ask mutithreading qns...Thanks a Lot form 10+ yrs exp guy from BLR,India.
@JakobJenkov
@JakobJenkov Ай бұрын
Thanks :-)
@_graymatter__
@_graymatter__ 3 жыл бұрын
I will come back and watch this once I am done with office work. Thanks for all the good work. Cheers
@JakobJenkov
@JakobJenkov 3 жыл бұрын
You are welcome! :-) ... I'll hold a warm copy of this video for you for when you return ;-)
@_graymatter__
@_graymatter__ 3 жыл бұрын
@@JakobJenkov Thanks. The world has turned cold and drab in most places. Little warmth is always appreciated :)
@LuneAgent
@LuneAgent 2 жыл бұрын
It's so satisfying to watch the tutorials in 4k
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Glad you think so ;-)
@tirthankarmitra2898
@tirthankarmitra2898 3 жыл бұрын
First of all Thanks a ton for all these excellent elaborated contents, it is truly admirable. On the context of "Parallel not concurrent" I think we can say that multiple instances of an application could run in parallel however in each application there is only one thread.
@JakobJenkov
@JakobJenkov 2 жыл бұрын
True. Multiple processes could run in parallel - even if each process only has one thread running internally.
@vamsi1701
@vamsi1701 3 жыл бұрын
I tried to understand this topic many times till now. This time I have confidence that I can explain others well, because I understood the concept. Thanks Jakob.
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Great! :-) ... I have tried myself to have problems understanding a topic - until I found the "right" explanation - one that I understand, that is! I am happy to be able to help others get to that point too :-)
@lupuionut6286
@lupuionut6286 3 жыл бұрын
The Java concurrency playlist is helping me get through college homework (thank you for that). They're well made and easy to understand. I do also appreciate that an experienced programmer like you decided to do this work basically for free.
@JakobJenkov
@JakobJenkov 3 жыл бұрын
I am glad you like them! :-) ... that's why I made them :-)
@manOfPlanetEarth
@manOfPlanetEarth 2 жыл бұрын
@@JakobJenkov Hello, Jakob) Last section, you talking about "parallel, not concurrent" case. Question: if one big task is broken into tasks (in differents threads of course), but there is only one CPU, will it be concurrency and not parallelism?😁
@shihore
@shihore 2 жыл бұрын
Recently I am taking the Parallel and Concurrent Programming course. Your explanation is very clear and thank you for making the video to let me have the basic idea before the course.
@JakobJenkov
@JakobJenkov 2 жыл бұрын
You are welcome! I am glad my video helped you! :-) ... I have a whole playlist of 21 videos in this topic - in case you are interested ;-)
@AMITPAUL-ty1hk
@AMITPAUL-ty1hk 11 ай бұрын
Well explained Jakob. Thanks for explaining the complex concept in a simple way...
@JakobJenkov
@JakobJenkov 11 ай бұрын
You are most welcome ! 😊
@ralphguichette9952
@ralphguichette9952 Жыл бұрын
FINALLY! Every tutorial and course I've taken could not explain this the way you just did. Rule: "If you can't teach it to me like I'm 5, you don't know it either". You sir, clearly know your stuff. Thank you! Please tell me you have courses I can buy from you.
@JakobJenkov
@JakobJenkov Жыл бұрын
Thank you very much for your kind words! :-) At the moment I do not have any specific courses (or similar) that you can buy. In the future I will probably have some books etc. - but they will most likely be related to a very specific project I am working on. There will be lots of basic to advanced stuff to learn from those too, though. But - not yet :-) You will see when it comes out - because I will be making videos about this project too :-)
@juanandrew1356
@juanandrew1356 Жыл бұрын
Mr. Jakob, your explanation is very good and I understand much better now for my Golang learning. Thank you
@JakobJenkov
@JakobJenkov Жыл бұрын
Great ! :-)
@gabrielxu2087
@gabrielxu2087 2 жыл бұрын
Best concurrency tutorial online!
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Thank you! :-)
@athisii_ekhe6167
@athisii_ekhe6167 2 жыл бұрын
Thank you for making it very clear. Great job!
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Thanks - and you are welcome! :-)
@bunthaideng2492
@bunthaideng2492 6 ай бұрын
That's awsome Jakob!
@JakobJenkov
@JakobJenkov 6 ай бұрын
Thank you !! 😊
@alessandroporfirio1910
@alessandroporfirio1910 3 жыл бұрын
Thank you for this video. It was very well explained.
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Thanks :-)
@aktchungrabanio6467
@aktchungrabanio6467 3 жыл бұрын
Excellent! So clear. Thank you.
@JakobJenkov
@JakobJenkov 3 жыл бұрын
You are welcome! Glad it was easy to understand :-)
@nfuryboss
@nfuryboss 2 жыл бұрын
Very well explained. In most real-world applications with multicore CPUs, it's a mixed concurrency and parallelism. So "parallelism" can be interpreted as a situation where you have a high percentage of parallel executions over concurrent executions. Vice versa. I think the concept of simultaneity of executions flow is important here.
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Thank you. Yes, there is a lot of parallel execution going on in multicore CPUs. Some threads may run on the same CPU, other threads may run on different CPUs etc. Additionally, you have the serially parallel instruction pipelines of the CPUs too, that also provide some level of parallelism - although within a thread - not between threads.
@lukashenrique4295
@lukashenrique4295 3 жыл бұрын
beautiful graphics. ty so much for the explanation!
@JakobJenkov
@JakobJenkov 3 жыл бұрын
You are welcome ! ... Hope it was easy to understand! :-)
@rajankumarverma507
@rajankumarverma507 Жыл бұрын
Great work, thanks for helping on Java.
@JakobJenkov
@JakobJenkov Жыл бұрын
Thanks - and you are welcome! :-)
@webizfabulous2535
@webizfabulous2535 6 ай бұрын
thank you! Love this video! Take care.
@JakobJenkov
@JakobJenkov 6 ай бұрын
You are welcome, and thank you too !! 😊
@sandyfernando9600
@sandyfernando9600 2 жыл бұрын
Thank you for the clear explanation !!!!
@JakobJenkov
@JakobJenkov 2 жыл бұрын
You are welcome!! :-)
@emonymph6911
@emonymph6911 3 жыл бұрын
Literally 0 dislikes speaks for itself... You're a god!
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Thanks :-D
@krishnamurthymadaraboina1556
@krishnamurthymadaraboina1556 9 ай бұрын
thank you , i undersood this concept now.
@JakobJenkov
@JakobJenkov 8 ай бұрын
You are welcome :-)
@bitcoindaddy748
@bitcoindaddy748 3 жыл бұрын
Marvelous explanation, thank you!
@JakobJenkov
@JakobJenkov 3 жыл бұрын
You are welcome :-)
@lukashenrique4295
@lukashenrique4295 3 жыл бұрын
"daddy, can i get a bitcoin pleasee?" idk why, I just thought that when I saw your name lolll
@nolanbyrnes8505
@nolanbyrnes8505 3 жыл бұрын
Well explained! Thank you!
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Thanks, and you are welcome 😊
@sonofgod00
@sonofgod00 3 жыл бұрын
great explanation for all. thank you.
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Thank you - and you are welcome :-)
@ffatheranderson
@ffatheranderson 3 жыл бұрын
Thank you very much Jakob.
@JakobJenkov
@JakobJenkov 3 жыл бұрын
You are welcome! :-)
@renandorneles3217
@renandorneles3217 11 ай бұрын
Damn, nice video!
@JakobJenkov
@JakobJenkov 11 ай бұрын
Thank you 😊
@jayaganthan1
@jayaganthan1 11 ай бұрын
Awesome explanation! Thanks
@JakobJenkov
@JakobJenkov 11 ай бұрын
You are welcome! :-) Glad to hear its useful!
@manoj.tyg01
@manoj.tyg01 3 жыл бұрын
Thanks for making video on this topic...enjoyed more than the blog :-)
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Thanks! Glad you like this one Manoj! Long time since we talked the last time, right? Usually on LinkedIn... :-)
@manoj.tyg01
@manoj.tyg01 3 жыл бұрын
@@JakobJenkov Yes, last time we talked on LinkedIn as you don't like social networking much facebook or whatsapp :-) I think study pattern is changing now.People are more interested in video content as video maker can express more as compared to blog and Listener can also play with any speed he/she likes.Earlier I used to keep 1.x but now I am comfortable with 1.5 or sometimes 2.0 and this is great experience. Hope you will make more content whenever you have time specially on distributed architecture and whatever you have done in last couple of years.
@shivam8837
@shivam8837 Жыл бұрын
Awesome explanation
@JakobJenkov
@JakobJenkov Жыл бұрын
Thanks ! :-)
@maxisperera3024
@maxisperera3024 2 жыл бұрын
Thanks SIR !! for the Great effort !!!
@JakobJenkov
@JakobJenkov 2 жыл бұрын
You are most welcome! :-)
@masoomsanadi
@masoomsanadi 10 ай бұрын
nicely explained. simple & neat
@JakobJenkov
@JakobJenkov 10 ай бұрын
Thank you ! :-)
@poosam4065
@poosam4065 2 жыл бұрын
Good video. Very clear content. :)
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Thank you very much!
@nazeeyashikalgar2428
@nazeeyashikalgar2428 3 жыл бұрын
Nice explanation! Please make more videos about latest concurrency api introduced in Java.
@JakobJenkov
@JakobJenkov 3 жыл бұрын
I will try :-)
@umitkirtil
@umitkirtil Жыл бұрын
Thats realy good explanation
@JakobJenkov
@JakobJenkov Жыл бұрын
Thank you! :-)
@iragideonkane4045
@iragideonkane4045 2 жыл бұрын
Thanks a million
@JakobJenkov
@JakobJenkov 2 жыл бұрын
You are welcome! :-)
@naej2549
@naej2549 4 ай бұрын
this video is awesome
@JakobJenkov
@JakobJenkov 4 ай бұрын
Thank you very much !! :-)
@yuzheding4436
@yuzheding4436 2 жыл бұрын
omg, this is so clear
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Thanks! Glad it was understandable :-)
@WizardOfArc
@WizardOfArc 3 жыл бұрын
Thanks for clearing this up for me 😀
@JakobJenkov
@JakobJenkov 3 жыл бұрын
You are welcome! :-)
@aghiadalzein3069
@aghiadalzein3069 2 жыл бұрын
That was great....
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Thanks! :-)
@krishnachaitu17
@krishnachaitu17 2 жыл бұрын
fantabulous, thanks for the great share
@JakobJenkov
@JakobJenkov 2 жыл бұрын
You are welcome! :-)
@sanjarcode
@sanjarcode Жыл бұрын
Thanks, awesome explanation. A video Idea - Concurreny vs Parallelism vs Asynchrony.
@JakobJenkov
@JakobJenkov Жыл бұрын
Java does not have async await features - if that is what you are referring to.
@muhammaddevanozaidan6837
@muhammaddevanozaidan6837 Жыл бұрын
nice explanation
@JakobJenkov
@JakobJenkov Жыл бұрын
Thanks :-)
@antonhen23
@antonhen23 3 жыл бұрын
Jakob, you have explained well the difference between concurrent and parallel execution in terms of CPU processes. But is there any difference in terms of sharing data? Is it possible to create 2 processes running on the different CPUs sharing the same data like counter variable, and the process is to read the value and inc it. I guess in previous videos when you're talking about 2 Threads sharing data, these 2 processes were executing on the same CPU concurrently. Is it possible that those 2 processes could have been executing on the 2 different CPUs in parallel? How synchronized block manages threads(processes) sharing data but running on the different CPUs?
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Yes, it is possible to share data between threads that run on different CPUs. And yes, volatile and synchronized keywords work the same in that situation. If you access a variable from within a synchronized block, only one thread can access it - regardless of how many CPUs your computer has running threads inside your application. Also, you are guaranteed that updates made by one thread to a variable from within a synchronized block is also visible to other threads - even if the threads run on different CPUs. The same is true about volatile variables.
@antonhen23
@antonhen23 3 жыл бұрын
@@JakobJenkov Thanks! It's clear now)
@ashutoshkedar1577
@ashutoshkedar1577 3 жыл бұрын
clear and concise explanation. Thankyou. Please do make a video on demonstration of java concurrent collections.
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Thank you! I may get around to making videos about the classes in java.util.concurrent soon. Until then, I have textural tutorials about them here: tutorials.jenkov.com/java-util-concurrent/index.html
@ashutoshkedar1577
@ashutoshkedar1577 3 жыл бұрын
@@JakobJenkov Thankyou
@boscooludhe7406
@boscooludhe7406 3 жыл бұрын
Nice Explanation
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Thanks :-)
@naej2549
@naej2549 4 ай бұрын
I am having so much fun right now
@JakobJenkov
@JakobJenkov 4 ай бұрын
Great! :-D
@jolskey
@jolskey Жыл бұрын
Hi Jakob. What do you exactly mean in CPU? Do you use CPU and CPU core interchangeably? Because as I know, computers usually come with one CPUs and multiple cores. So let's take Intel Core i7, is i7 a CPU or it has bunch of CPUs? Thanks.
@JakobJenkov
@JakobJenkov Жыл бұрын
In terms of multithreading just think multiple cores. I don't think it makes a huge difference concurrency-wise whether you have one CPU with 8 cores / 16 threads, or 8 CPUs. You have to deal with the same issues.
@akshatjain3010
@akshatjain3010 11 ай бұрын
Thanks a ton or the excellent video! Could you please help me understand in case of Parallelism splitting of a task(thread) done in the program(By Programmer, is so how?) or it is done by the compiler while generating the machine code or CPU while executing the instructions?
@JakobJenkov
@JakobJenkov 11 ай бұрын
Splitting a job up into multiple smaller tasks that cen be processed in parallel must be done by the programmer. The compiler does not know enough about the tasks your code is performing to know how to do that, in most cases. In some cases, if you give some hints, perhaps it can be done more automatically - and sometimes at runtime by e.g. TornadoVM or other tools. But the developer is at this point in time still required to at least hint at how to break up the task.
@akshatjain3010
@akshatjain3010 11 ай бұрын
@@JakobJenkov What are the ways in programming through which a task (Thread) can be split into multiple subtasks? If you can give any hint in any language.
@SyedGm
@SyedGm Ай бұрын
@Jakob, do you have git repository for all these tutorials of threads ? the examples which you are explaining in the videos.
@JakobJenkov
@JakobJenkov Ай бұрын
I have some examples in my Java Examples GitHub repo (link below) - but not yet so many: github.com/jjenkov/java-examples
@rajankumarverma507
@rajankumarverma507 Жыл бұрын
Hi jakob, can you please create any course on how to do real time project development for experienced Java developer for production ready project. It should have source code for real time Java project. Thanks for this video.
@JakobJenkov
@JakobJenkov Жыл бұрын
Hi Rajan, I will eventually make some videos about Realtime Architectures - but it's a big topic with lots of details, nuances and tradeoffs, so I don't think I can just make a "ready-to-go" template you can just start from. But I can cover various topics that can help you design your own realtime architecture, or at least take steps towards a realtime architecture.
@KeplerEmeritus
@KeplerEmeritus 2 жыл бұрын
Good video! Only thing I think is that "CPU" could say "Core" in the example images.
@JakobJenkov
@JakobJenkov 2 жыл бұрын
True... but I decided to keep it simple :-)
@sjm2256
@sjm2256 Жыл бұрын
would you say that parallelism is the same as parallel concurrent execution, except its concerned with a single task being broken up rather than different tasks?
@JakobJenkov
@JakobJenkov Жыл бұрын
That is my understanding of the official distinction, yes. Approximately.
@eternalgreed6715
@eternalgreed6715 Жыл бұрын
Hi, Jacob! If i have 1 core(CPU )CPU and run 2 instances of the same application with only 1 thread (main) in each instance, does it mean parallel execution? Or Parallel execution of any application, process might be only on 2+ cpu? Sorry for possible obvious question.
@JakobJenkov
@JakobJenkov Жыл бұрын
Parallel execution would require more than one CPU. Otherwise it is just concurrent execution
@JakobJenkov
@JakobJenkov Жыл бұрын
Or at least more than one CPU core...
@webmaster246
@webmaster246 2 жыл бұрын
Has Parallelism to do anything with fork() specifically for Node.js ?
@JakobJenkov
@JakobJenkov 2 жыл бұрын
I am not an expert in Node.js - but I think fork() runs a JavaScript in a new process - which might be able to run in parallel with the process spawning it. But - please double check the Node.js docs !!
@emonymph6911
@emonymph6911 3 жыл бұрын
Does anyone know if any of these three backend languages have both concurrency and parallelism? Node/Express Django Go I want to become a multi-thread API dev. I don't care about what is 'popular' now. I just want what has the best foundation for concurrency and parallelism.
@JakobJenkov
@JakobJenkov 3 жыл бұрын
I don't know myself, actually. I vaguely remember something about Node having support for multiple threads that can run on multiple CPU cores, but I don't know how it works internally.
@omnipoten8
@omnipoten8 3 жыл бұрын
Thanks for the nice explanation . I have got a question here . If we have two threads and two CPUs. CPU-1 is executing thread-1 and CPU-2 is executing thread-2. Hence we have parallelism here. Now if at some point of time one of the threads takes the monitor of a lock and halts the execution of other thread until the monitor is released and acquired by other thread, in that case which one is true : 1. Thread-1 and thread-2 are running concurrently 2. Thread-1 and thread-2 were running in parallel , but at that point of time when monitor lock was acquired they ran concurrently . 3. Thread-1 and thread-2 are running in parallel
@JakobJenkov
@JakobJenkov 3 жыл бұрын
If Thread 1 takes a monitor object, and Thread 2 does NOT try to take that monitor at the same time, Thread 1 and Thread 2 are still running in parallel. If Thread 2 DOES try to take the monitor object while Thread 1 holds it, Thread 2 will be blocked until Thread 1 releases the monitor object - in which case they are not running in parallel while Thread 2 is waiting.
@omnipoten8
@omnipoten8 3 жыл бұрын
@@JakobJenkov Thank you very much Jacob for your reply . Very clear and concise .
@jeromebarbier5295
@jeromebarbier5295 2 жыл бұрын
Concurrency looks like async JavaScript. Did I miss some key difference here?
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Not exactly. Async in Java still runs within a single thread, as far as I know. Concurrency in Java could be achieved using multiple threads - yet still running on the same CPU (or different CPUs).
@jeromebarbier5295
@jeromebarbier5295 2 жыл бұрын
@@JakobJenkov I see. Thank you.
@AhmedMohamed-mq2xz
@AhmedMohamed-mq2xz 2 жыл бұрын
When you say CPUs do you mean CPU cores?
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Does it matter?
@AhmedMohamed-mq2xz
@AhmedMohamed-mq2xz 2 жыл бұрын
​@@JakobJenkov First of all, please excuse my lack of knowledge as I'm still learning. I believe it matters because it sounds odd to say: Imagine we have a computer with 2/multiple "CPUs" 2:10 3:19 instead of the commonly known "CPU Cores" with 2 Threads each. I first thought this might be possible with dual CPU servers, which you didn't mention, until you mentioned "8 CPUs" 6:37 . I'm only pointing this out because I got confused and wanted to get more clarification.
@cclementson1986
@cclementson1986 28 күн бұрын
You tried so hard to be clear but you failed and even in the comments you are sticking to it. People are asking, do you mean CPU or CPU core. It matters!!! Stop saying it doesn't. The average person does NOT have a multi CPU machine. So it matters. By not CLEARLY defining what you mean, it causes more confusion, especially to those trying to learn the VERY difficult concept. Say what you mean, say CPU Core. It means something.
@JakobJenkov
@JakobJenkov 18 күн бұрын
Allright - I will say CPU core in the future... I don't personally think it makes a big difference, except a bit about the internal design with caches etc. But I can refer to the cores as "cores" ... We are also getting a GPU API in Java in the future, and I guess we also just call it "one GPU with many cores".
@cclementson1986
@cclementson1986 18 күн бұрын
@@JakobJenkov I appreciate your response. I really liked your video but I did have to look at a couple more to fully understand that you meant CPU core. Thank you for taking the time and being willing to adapt. As a consumer of content, I can only appreciate those who are willing to accept feedback and adapt. Thank you for your response.
Thread Pools in Java
18:04
Jakob Jenkov
Рет қаралды 64 М.
Concurrency is not Parallelism by Rob Pike
31:22
gnbitcom
Рет қаралды 124 М.
KINDNESS ALWAYS COME BACK
00:59
dednahype
Рет қаралды 143 МЛН
КАРМАНЧИК 2 СЕЗОН 7 СЕРИЯ ФИНАЛ
21:37
Inter Production
Рет қаралды 542 М.
3M❤️ #thankyou #shorts
00:16
ウエスP -Mr Uekusa- Wes-P
Рет қаралды 15 МЛН
Concurrency vs Parallelism
8:23
Defog Tech
Рет қаралды 241 М.
Java Concurrency and Multithreading - Introduction
14:32
Jakob Jenkov
Рет қаралды 234 М.
Concurrency, Introduction - مقدمة بالعربي
14:43
Java Lock
28:51
Jakob Jenkov
Рет қаралды 43 М.
Parallelism vs Concurrency
6:30
CodeVault
Рет қаралды 12 М.
Concurrency vs Parallelism in Node.js
7:47
Mehul - Codedamn
Рет қаралды 40 М.
Опять съемные крышки в смартфонах? #cmf
0:50
Зачем ЭТО электрику? #секрет #прибор #энерголикбез
0:56
Александр Мальков
Рет қаралды 219 М.
WATERPROOF RATED IP-69🌧️#oppo #oppof27pro#oppoindia
0:10
Fivestar Mobile
Рет қаралды 18 МЛН
😱Хакер взломал зашифрованный ноутбук.
0:54
Последний Оплот Безопасности
Рет қаралды 528 М.
iPhone socket cleaning #Fixit
0:30
Tamar DB (mt)
Рет қаралды 6 МЛН
PART 52 || DIY Wireless Switch forElectronic Lights - Easy Guide!
1:01
HUBAB__OFFICIAL
Рет қаралды 44 МЛН