29. Multithreading and Concurrency in Java: Part1 | Threads, Process and their Memory Model in depth

  Рет қаралды 36,537

Concept && Coding - by Shrayansh

Concept && Coding - by Shrayansh

8 ай бұрын

➡️ Notes: Shared in the Member Community Post (If you are Member of this channel, then pls check the Member community post, i have shared the Notes link there)
➡️ Join this channel to get access to member only perks:
/ @conceptandcoding
Overall Important Subtopics of Multithreading and Concurrency:
----------------------------------------------------------------------------------------------------------
- Introduction of Multithreading: (Covered in this Video)
* Definition of Multithreading
* Benefits and Challenges of Multithreading
* Processes v/s Threads
* Multithreading in Java
- Java Memory Model of Process and thread (Covered in this Video)
- Basics of Threads - Part1:
* Creating Threads
* Extending the Thread Class
* Implementing the Runnable Interface
* Thread Lifecycle
* New
* Runnable
* Blocked
* Waiting
* Timed Waiting
* Terminated
- Basics of Thread - Part2 : Inter Thread Communication and Synchronization
* Synchronization and Thread Safety
* Synchronized Methods
* Synchronized Blocks
* Inter-Thread Communication
* wait(), notify(), and notifyAll() methods
* Producer-Consumer Problem - Assingment

- Basics of Threads - Part3
* Producer-Consumer Problem - Solution discuss
* Stop, Resume, Suspended method is deprecated, understand why and its solution
* Thread Joining
* Volatile Keyword
* Thread Priority and Daemon Threads
- Some Advanced Topics
* Thread Pools
* Executor Framework
* ThreadPoolExecutor
* Callable and Future
* Fork/Join Framework
* ThreadLocal in Multithreading
- Concurrency Utilities
* java.util.concurrent Package
* Executors and ExecutorService
* Callable and Future
* CompletableFuture
* ScheduledExecutorService
* CountDownLatch, CyclicBarrier, Phaser, and Exchanger
- Concurrent Collections (already discussed during Collections topic, will provide working example for this)
* ConcurrentHashMap
* ConcurrentLinkedQueue and ConcurrentLinkedDeque
* CopyOnWriteArrayList
* BlockingQueue Interface
* ArrayBlockingQueue
* LinkedBlockingQueue
* PriorityBlockingQueue
- Atomic Variables
* AtomicInteger, AtomicLong, and AtomicBoolean
* AtomicReference and AtomicReferenceArray
* Compare-and-Swap Operations
- Locks and Semaphores
* ReentrantLock
* ReadWriteLock
* StampedLock
* Semaphores
* Lock and Condition Interface
- Parallel Streams (already discussed during Stream topic, will provide working example for this)
- Best Practices and Patterns
* Thread Safety Best Practices
* Immutable Objects
* ThreadLocal Usage
* Double-Checked Locking and its Issues
* Concurrency Design Patterns
- Common Concurrency Issues and Solutions
* Deadlocks
* Starvation
* Livelocks
* Race Conditions
* Strategies for Avoiding Concurrency Issues
- Java 9+ Features
* Reactive Programming with Flow API
* CompletableFuture Enhancements
* Process API Updates
- Java 11+ Features
* Local-Variable Type Inference (var keyword)
* Enhancements in Optional class
* New Methods in the String class relevant to concurrency

Пікірлер: 103
@chiveshupneja1593
@chiveshupneja1593 7 ай бұрын
Such a crystal clear explanation of core concepts, I don't think no body explains so well even in highly paid courses. Thanks Shreyansh!!
@ConceptandCoding
@ConceptandCoding 7 ай бұрын
Thanks 🙏
@iqrarahmad59
@iqrarahmad59 26 күн бұрын
those who sell high paid course are the ones who got laid off or quid due to lack of real knowledge
@DurgaShiva7574
@DurgaShiva7574 5 ай бұрын
what a lecture, what a learning, awesome, as a professional, i didn't knew 10% of what u taught today, kudos to you
@ConceptandCoding
@ConceptandCoding 5 ай бұрын
thanks
@afterfridaystories
@afterfridaystories 2 ай бұрын
Just Loved It ! 1 complete / all 10 Multithreading videos. This weekend I will complete all 10 !
@ratansarkar7444
@ratansarkar7444 5 ай бұрын
How someone can give indept knowledge for free..I'm glade to have you as java trainer
@ConceptandCoding
@ConceptandCoding 5 ай бұрын
happy learning
@saswatsenapati7870
@saswatsenapati7870 9 күн бұрын
The difference here is the blend of java concepts + core cs concepts. Very rares you find some one teaching a language actually mapping with its actual cs core concepts.
@vishalakasnehashis9747
@vishalakasnehashis9747 Ай бұрын
Literally this is the best video on such a core and challenging concept to grasp at the root level. Heartfelt thanks to you for presenting this video series in crystal clear .Thank you once again for your devotion and making the community thrive
@stepswithvishnu2924
@stepswithvishnu2924 6 ай бұрын
Worth to have your channel's membership. Nicely explained.
@ConceptandCoding
@ConceptandCoding 6 ай бұрын
🙏
@fa1con989
@fa1con989 8 ай бұрын
Eagerly waiting for the spring playlist
@zaheerabass7955
@zaheerabass7955 8 ай бұрын
Point to point brings very much clearity. Thank You
@ConceptandCoding
@ConceptandCoding 8 ай бұрын
thanks
@chhitijsrivastava793
@chhitijsrivastava793 12 күн бұрын
Really nice lecture, you made my day. I was literally searching for a Java course online and your course series is truly awesome. Thanks for your effort; such high-quality resources are rarely found almost free anywhere else. Thanks, Shreyansh ❣
@ConceptandCoding
@ConceptandCoding 12 күн бұрын
Glad to hear that
@Sushil2874
@Sushil2874 8 ай бұрын
Wooo...Take a bow.... Such a great explanation..🙌 Really looking forward for upcoming ones for this topic. Also, show the things with code execution wherever it is possible, which you always does so. Thank you!
@ConceptandCoding
@ConceptandCoding 8 ай бұрын
Sure, thanks 🙏
@Rameez-Raja
@Rameez-Raja 12 күн бұрын
you made my day.. Thanks for the crystal clear explanation in simple terms ❤🎉
@imrohan97
@imrohan97 2 ай бұрын
God-level concepts.Thanks for such valuable content.
@ConceptandCoding
@ConceptandCoding 2 ай бұрын
thanks
@AkashGupta-jb7zj
@AkashGupta-jb7zj 4 ай бұрын
One of the Best Vedios of Explaining the working of Threads in Java, totally loved it, it also cleared my doubt regarding the CPU cores and the Thread allocation to them, how they work in parallel and with context switching. Thank You So Much and Kudos to You!!
@ConceptandCoding
@ConceptandCoding 4 ай бұрын
thanks
@keshavdeosharma7222
@keshavdeosharma7222 2 ай бұрын
Very nice explaination. Thank you Sir
@SahithiMangalapalli
@SahithiMangalapalli 4 ай бұрын
It's absolutely clear and such a great learning, I can't thank you enough for sharing such valuable knowledge
@ConceptandCoding
@ConceptandCoding 4 ай бұрын
thanks
@drissaitkassimusic
@drissaitkassimusic 2 ай бұрын
You deserve more than million subs 👍👍👍👍👍
@nikhilkumar3124
@nikhilkumar3124 8 ай бұрын
Good videos. Cleared lot of doubts.
@ConceptandCoding
@ConceptandCoding 8 ай бұрын
Thanks
@amalamal3312
@amalamal3312 2 ай бұрын
wow .just amazing
@mithunvasisht3176
@mithunvasisht3176 8 ай бұрын
@Shreyansh Great content. One thing I wanted to know is where is Code Segment present? In the ROM/EPROM? What about extra segment ? In the RAM? This needs to be known. Probably a small wrapper class on CPU architecture and where different segments are located shall help understand multithreading better
@sujeetbadnale9441
@sujeetbadnale9441 7 ай бұрын
God Bless You Brother😊. It was indepth and in one flow. We kind of learn in peaces and we forget, but tought us in peaces and also combined them in a single flow, which is more beautiful. You are a great god gifted teacher, carry on. Keep Sharing. Be Blessed and Be Blessing for others as you already are 😊 One small request though, the last part where the actual execution that happens on CPU was bit unclear to me, if possible could be please create a seperate video which explains that in details?
@ConceptandCoding
@ConceptandCoding 7 ай бұрын
Thanks, sure will cover
@vaibhavjain1124
@vaibhavjain1124 5 ай бұрын
Truely very great content man!! Just one suggestion, is it possible that when you research for these videos you can mark the sources too any books articles etc. And for this thread series any suggestion for any good resources explaining with this level of deepness or any sources you used can you link them.
@mehnaazmohiuddin
@mehnaazmohiuddin 8 ай бұрын
you are doing a great job. Keep it up
@mehnaazmohiuddin
@mehnaazmohiuddin 8 ай бұрын
one small thing that took me to other articles was what register is storing .. seems like its saving the operator , operands. there are multiple registers from what i have come to understand .. i guess atleast 3 to store operator , operators and accumulator. to come back to do what it was doing. Simply great work though . This must be taking so much of your time! good job again
@yogendrasingh-nz3pw
@yogendrasingh-nz3pw 2 күн бұрын
Thanks a lot for this wonderful knowledge sharing. Can someone please tell where is the remaining videos for multithreading part 2
@asharya5311
@asharya5311 2 ай бұрын
@Shreyansh Jain Thank you for the informative lectures, recently took the membership, but not able to find multithreading notes link in member community post. Please help.
@ayush24jai
@ayush24jai 6 ай бұрын
VIDEO 3 My Motive for commenting: Watching all videos of sir/bhaiya , to get his personal guidance and referals for sde job . My Feeling : Amazing to learn from someone in big position in paypal company Want to be under ur guidance and chatrachaaya Thankyou Shrayansh sir/bhaiya
@siddhantprakash.
@siddhantprakash. 2 ай бұрын
maza aaya kaafi din baad kuch padh ke. #Day4 of 7Days of java
@lakshmanankanthi7158
@lakshmanankanthi7158 6 ай бұрын
Hi sir. Thanks for the clear explanation, just a doubt. What is the difference between JVM heap size and JVM instance heap size? Is there something like global JVM? Thanks
@jayendrasingh9260
@jayendrasingh9260 8 ай бұрын
One of the best 👍
@ConceptandCoding
@ConceptandCoding 8 ай бұрын
Thanks
@theunusual4566
@theunusual4566 6 ай бұрын
Thank you.
@kent.johnson
@kent.johnson 2 ай бұрын
Nice
@car_holic1995
@car_holic1995 8 ай бұрын
Bhai itna detail me self study karna ho toh?
@kritisingh1347
@kritisingh1347 3 ай бұрын
thanks shreyansh
@aashiarora3150
@aashiarora3150 6 ай бұрын
@Concept_&&_Coding How does JVM know how many threads it requires to execute a program?
@Ashish-hr3zn
@Ashish-hr3zn 2 ай бұрын
Bit a MIxture of Compiler , Os , Computer Architechture ,nice video
@LaptopBackup-bo6kp
@LaptopBackup-bo6kp 6 ай бұрын
Is data segment alias for metaspace?
@krishnendughosh2368
@krishnendughosh2368 6 ай бұрын
22:15 shouldnt we call this Interpreted bytecode instead of compiled bytecode? Btw I have faced this issue of writing junits for multithreading and also debugging issues. We used webclient for rest call and it was customized heavily, so a big chunk of code was not under any junits. It reduced our ovrall test coverage but mejority of use were not able to write test for it, not even the developer who wrote the class at the first place. Can you please add one video to address these two challenges you mentione?
@Krishna-iu4zp
@Krishna-iu4zp 3 ай бұрын
context swithing is b/w processes or b/w thread or both ? (47:08)
@ruthvikreddy1625
@ruthvikreddy1625 5 ай бұрын
why is thread the smallest sequence of instruction? What does smallest here refer to?
@rajatmehta7545
@rajatmehta7545 7 ай бұрын
While we are increasing the JVM memory to say 5-6 GB (max) and 256 mb (min) ... how this max value is decided.. for example if the application is deployed on AWS EC2 instance server with say RAM => 4GB and ROM 90 GB, which one contributes to the JVM memory, RAM or ROM?
@adityagupta375
@adityagupta375 5 ай бұрын
It's amazing the details shared in the video, please let us know where do you get all the knowledge from, the books you read or any kind of other resources. It will be very helpful for self-study and upskilling.
@ConceptandCoding
@ConceptandCoding 5 ай бұрын
thanks. Many with experience in would say Aditya. Its been 8yrs and still working with Java tech stack only
@saurbhbansal7408
@saurbhbansal7408 Ай бұрын
Hi very useful video, but I guess you didn't make a playlist for this. It's a little difficult to find the next part's video in this sequence.
@pulkitxd
@pulkitxd 8 ай бұрын
@Shrayansh bhai, Kindly enable download on member videos. Some of us have subscribed to membership, download & watch videos offline, especially I use my commute time to watch videos offline.
@ConceptandCoding
@ConceptandCoding 8 ай бұрын
ack, will do buddy
@abc-ym4zs
@abc-ym4zs 8 ай бұрын
Sir i want your suggestion i not able to understand the reactjs and backend technologies 😢 and i am not able to improve my problem solving skills i am in third year loosing interest in studies can u tell me how to get back to track
@nishantkumar6116
@nishantkumar6116 5 ай бұрын
Nice Explanation...please create videos on Aspect Oriented Programming, I've got several question from AOP and spring AOP in my recent interviews
@ConceptandCoding
@ConceptandCoding 5 ай бұрын
ack
@rajanikushwah1414
@rajanikushwah1414 8 ай бұрын
Following java Playlist and explanation 👌. When can we expect spring Playlist ?
@ConceptandCoding
@ConceptandCoding 8 ай бұрын
After Java, Java thodi hi bachi hai bas
@kamalrai286
@kamalrai286 19 күн бұрын
If there is one CPU and one register so how is it possible for thread having their individual registers
@nitishchaudhary7777
@nitishchaudhary7777 3 ай бұрын
Bro, unable to find part 2, is that uploaded/created?
@ConceptandCoding
@ConceptandCoding 3 ай бұрын
video no 30. is part2
@garvitjain9933
@garvitjain9933 2 ай бұрын
Does JIT create all the required threads before running a process? Refer to the video at 32:30. This seems counter intutive
@JaiChandraSekarRK
@JaiChandraSekarRK 3 ай бұрын
brilliant explanation, thoroughly enjoyed it...where can i find part 2 and so on?
@ConceptandCoding
@ConceptandCoding 3 ай бұрын
check the playlist 30th no video is part 2
@Randomvideo2610
@Randomvideo2610 8 ай бұрын
what happens for api call it create separates process for each api call and allocates heap memory.
@jayendrasingh9260
@jayendrasingh9260 8 ай бұрын
Each api calls his handle by spring internal threads
@karmicveda9648
@karmicveda9648 8 ай бұрын
🙌
@nirajosh
@nirajosh 6 ай бұрын
Hey Shreyansh, Any idea about how virtual threads are working ? Is Virtual thread same as a Thread ? if possible, Can you come up with some sort of video which will explain Virtual Thread ?
@ConceptandCoding
@ConceptandCoding 6 ай бұрын
Hi virtual thread is not same as Thread but they are backward compatible. In our traditional thread, JVM create respective native thread (OS level Kernel thread). so you can say JVM provide us the abstraction, when we say Thread.start(), it actually tells OS to create new native thread. But Virtual thread, introduced in Java19, here JVM takes the responsibility of managing the threads and it creates many virtual thread and map to very less number of native thread. Means Multiple virtual thread can work on single virtual thread. Virtual thread provides backward compatability, i can create a video of it. But i need to install latest JDK for it :) will do it later and create a video. But i know this info will help you in clearing your doubt.
@gauravraj2604
@gauravraj2604 6 ай бұрын
If I don't specify the heap memory size at the time of process execution, how much heap memory will be allocated to this process then?
@ConceptandCoding
@ConceptandCoding 6 ай бұрын
Default values are used which depends on system configuration and JVM. Generally min geap is 1/64 of total RAM. And Max heap is 1/4. But these values can change depending upon the system. There is a command too, through which you can know how much default heap value is set. I will look for that command and share with you.
@gauravraj2604
@gauravraj2604 6 ай бұрын
@@ConceptandCoding thank you for your response . Please do let me know the command.
@kaushikghosh8406
@kaushikghosh8406 6 ай бұрын
What algorithm does this context switching follow? FIFO? Shortest job? Round robin?
@ConceptandCoding
@ConceptandCoding 6 ай бұрын
its depends on scheduler to scheduler, various algo like priority based scheduling and there is one more time-sharing scheduling algo is used. but i need to check more on that.
@umairalvi7382
@umairalvi7382 23 күн бұрын
Why does it never happen that multiple threads execute the same statement multiple times how is it distributed among threads??
@harshitanand7349
@harshitanand7349 Ай бұрын
The Physical Memory in the diagram is RAM, right? Let’s say I have a 8gb RAM system and 600mb are free. If I do - java -Xms1g -Xmx2g Test Will it give OutOfMemoryError ?
@CodeTonics
@CodeTonics Ай бұрын
how can i download the notes
@gauravraj2604
@gauravraj2604 7 ай бұрын
Really liking your explanation. 1 doubt I had. Where exactly we tell how much heap memory to be allocated while creating a process?
@gauravraj2604
@gauravraj2604 7 ай бұрын
sorry got it. at the time of process execution itself we specify memory. e.g java . However, if I don't specify the heap memory size at the time of process execution, how much heap memory will be allocated to this process then?
@ConceptandCoding
@ConceptandCoding 7 ай бұрын
@@gauravraj2604 yes
@gauravraj2604
@gauravraj2604 7 ай бұрын
@@ConceptandCoding However, if I don't specify the heap memory size at the time of process execution, how much heap memory will be allocated to this process then?
@imrohan97
@imrohan97 2 ай бұрын
A 19:11, how does it get decided that how much Total JVM Heap Memory will be allocated
@imrohan97
@imrohan97 2 ай бұрын
Also, at 20:30, how much memory is allocated to the code segment, data segment, register, stack, and counter together? Is it different from heap memory?
@soumyaprakashsasmal6770
@soumyaprakashsasmal6770 6 ай бұрын
I have been thinking my professor made me understood OS very clear during college....I was wrong the whole time
@car_holic1995
@car_holic1995 8 ай бұрын
If coder dont create threads exclusively..task is completed by only main thread?
@ConceptandCoding
@ConceptandCoding 8 ай бұрын
Right
@sargamgoyal4161
@sargamgoyal4161 8 ай бұрын
Please make video on lambda functions also.
@ConceptandCoding
@ConceptandCoding 8 ай бұрын
It's already there, pls check previous videos in Java playlist buddy
@balakrushnabehera1631
@balakrushnabehera1631 4 ай бұрын
Hi Shreyansh why doesn't the below code work asproducer and consumer problem's solution import java.util.*; class Producer { Queue queue; Producer(Queue queue){ this.queue= queue; } public void produce(int data) throws Exception{ synchronized(queue){ while(queue.size() == 3){ //waiting for consumer to consume items System.out.println("waiting for consumer to consume items"); wait(); } System.out.println("Added item: " + data); queue.add(data); notify(); } } } class Consumer { Queue queue; Consumer(Queue queue){ this.queue= queue; } public void consume() throws Exception{ synchronized(queue){ while(queue.isEmpty()){ //waiting for producer to add items into queue System.out.println("waiting for producer to add items into queue"); wait(); } System.out.println("Removed: " + queue.poll() + " Current Queue Size is: " + queue.size()); notify(); } } } public class Main{ public static void main(String[] args) throws Exception{ Queue sharedQueue= new PriorityQueue(3); Producer producer= new Producer(sharedQueue); Consumer consumer= new Consumer(sharedQueue); Thread producerThread= new Thread(() -> { try{ for(int i= 0; i { try{ for(int i= 0; i
@ConceptandCoding
@ConceptandCoding 4 ай бұрын
ack will check buddy
@user-vj4li7cc8v
@user-vj4li7cc8v 5 ай бұрын
@Shreyansh Great Explained but where is part 2 video?
@ConceptandCoding
@ConceptandCoding 5 ай бұрын
already uploaded buddy 7-8 parts are there all uploaded
@atulvidyarthi9952
@atulvidyarthi9952 8 күн бұрын
Where is metaspace in this?
@car_holic1995
@car_holic1995 8 ай бұрын
Please include coding also bhai..
@ConceptandCoding
@ConceptandCoding 8 ай бұрын
I will, this is fundamental video, what is process and thread. Thread creation will go next with coding buddy
@Shadabkhan-tz7uv
@Shadabkhan-tz7uv 18 күн бұрын
Who is bro?💀🙌
Java Multithreading | Lifecycle of thread in java | Part - 1
11:59
Simple Snippets
Рет қаралды 4,5 М.
Stupid Barry Find Mellstroy in Escape From Prison Challenge
00:29
Garri Creative
Рет қаралды 21 МЛН
Osman Kalyoncu Sonu Üzücü Saddest Videos Dream Engine 170 #shorts
00:27
Is it Cake or Fake ? 🍰
00:53
A4
Рет қаралды 20 МЛН
9. Java Memory Management and Garbage Collection in Depth
48:48
Concept && Coding - by Shrayansh
Рет қаралды 48 М.
Multithreading in Java Explained in 10 Minutes
10:01
Coding with John
Рет қаралды 884 М.
FANG Interview Question | Process vs Thread
3:51
ByteByteGo
Рет қаралды 284 М.
The Java memory model explained, Rafael Winterhalter
48:01
Bulgarian Java User Group
Рет қаралды 16 М.
Is it concurrent or parallel?
3:48
Jacob Sorber
Рет қаралды 19 М.
Asynchronous Programming in Java using Virtual Threads, Venkat Subramaniam
49:16
Bulgarian Java User Group
Рет қаралды 10 М.
Stupid Barry Find Mellstroy in Escape From Prison Challenge
00:29
Garri Creative
Рет қаралды 21 МЛН