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

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 ก.ย. 2024
  • ➡️ 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

ความคิดเห็น • 119

  • @chiveshupneja1593
    @chiveshupneja1593 10 หลายเดือนก่อน +22

    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  10 หลายเดือนก่อน +1

      Thanks 🙏

    • @iqrarahmad59
      @iqrarahmad59 4 หลายเดือนก่อน +2

      those who sell high paid course are the ones who got laid off or quid due to lack of real knowledge

  • @car_holic1995
    @car_holic1995 11 หลายเดือนก่อน +8

    Bhai itna detail me self study karna ho toh?

  • @saswatsenapati7870
    @saswatsenapati7870 3 หลายเดือนก่อน +4

    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.

  • @PlugNPlay960
    @PlugNPlay960 2 หลายเดือนก่อน +4

    I just finished watching this video and I wanted to take a moment to commend you on the fantastic job you did.
    Your clear explanations and engaging presentation made complex concepts easy to understand. The way you break down the information is amazing.
    It's evident that you put a lot of effort into your content, and it truly shows.
    Thank you for creating such valuable and insightful videos that make learning enjoyable!

  • @knpragash
    @knpragash 21 วันที่ผ่านมา +3

    You have the GIFT in Teaching !

  • @DurgaShiva7574
    @DurgaShiva7574 8 หลายเดือนก่อน +7

    what a lecture, what a learning, awesome, as a professional, i didn't knew 10% of what u taught today, kudos to you

  • @ratansarkar7444
    @ratansarkar7444 8 หลายเดือนก่อน +5

    How someone can give indept knowledge for free..I'm glade to have you as java trainer

  • @SahithiMangalapalli
    @SahithiMangalapalli 7 หลายเดือนก่อน +3

    It's absolutely clear and such a great learning, I can't thank you enough for sharing such valuable knowledge

  • @MAHALAKSHMIVEERARAJ
    @MAHALAKSHMIVEERARAJ 13 วันที่ผ่านมา +1

    Great explanations and main thing is that you are teaching everything based on your real industry experiences. Great learning experience! Heartful Thanks to you!

  • @sujeetbadnale9441
    @sujeetbadnale9441 10 หลายเดือนก่อน +3

    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?

  • @soumyaprakashsasmal6770
    @soumyaprakashsasmal6770 9 หลายเดือนก่อน +1

    I have been thinking my professor made me understood OS very clear during college....I was wrong the whole time

  • @adhyanneekhra4853
    @adhyanneekhra4853 2 หลายเดือนก่อน

    When I run
    Java -Xms256m -Xmx2g Test
    What will be the total JVM heap memory allocated.
    How much each process JVM instance will get if I have 2 process running.
    And how it will be decided?

  • @afterfridaystories
    @afterfridaystories 5 หลายเดือนก่อน +2

    Just Loved It ! 1 complete / all 10 Multithreading videos. This weekend I will complete all 10 !

  • @rajanikushwah1414
    @rajanikushwah1414 11 หลายเดือนก่อน +2

    Following java Playlist and explanation 👌.
    When can we expect spring Playlist ?

    • @ConceptandCoding
      @ConceptandCoding  11 หลายเดือนก่อน +1

      After Java, Java thodi hi bachi hai bas

  • @harshitanand7349
    @harshitanand7349 4 หลายเดือนก่อน

    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 ?

  • @AkshayAgarwalCoding
    @AkshayAgarwalCoding 19 วันที่ผ่านมา

    Hi Shrayansh,
    Great, video once again but where is part 2?

  • @piyushjainwork01
    @piyushjainwork01 27 วันที่ผ่านมา

    Also Can you please brief me about how the metaspace came in picture and in which memory it will get allocated. from instance of JVM or the central JVM or The natice memory?

  • @fa1con989
    @fa1con989 11 หลายเดือนก่อน +3

    Eagerly waiting for the spring playlist

  • @imrohan97
    @imrohan97 6 หลายเดือนก่อน +2

    God-level concepts.Thanks for such valuable content.

  • @Rameez-Raja
    @Rameez-Raja 3 หลายเดือนก่อน +1

    you made my day.. Thanks for the crystal clear explanation in simple terms ❤🎉

  • @piyushjainwork01
    @piyushjainwork01 หลายเดือนก่อน

    I am struck 35:00 second where i am not able to understand who will start the main thread?

  • @sweetygangane4551
    @sweetygangane4551 2 หลายเดือนก่อน

    Teaching is good but... This unlocking vdos not giving so much link

  • @AmanKumarSamal
    @AmanKumarSamal 21 วันที่ผ่านมา

    Thank you for such a nice explanation!

  • @CodeTonics
    @CodeTonics 4 หลายเดือนก่อน +1

    how can i download the notes

    • @adhyanneekhra4853
      @adhyanneekhra4853 2 หลายเดือนก่อน

      Yeah even I am not able to download Zoho one

  • @pulkitxd
    @pulkitxd 11 หลายเดือนก่อน +1

    @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.

  • @tomorrowcut
    @tomorrowcut หลายเดือนก่อน

    Hi Shrayansh,
    Can you please help with an answer?
    Compilation (javac Test.java): generates bytecode that can be executed by JVM.
    Execution (java Test): at this point, JVM starts the new Process, here Test is the class that has the "public static void main(String args])" method.
    In your notes above, it is stated that JVM starts a process.
    and later you said that once the process is created, a new JVM instance is created.
    Are there two JVM instances, one which creates a process and the other one that is being created once the process is created?

    • @coolone5561
      @coolone5561 หลายเดือนก่อน +1

      Edited: When you run "java Program", OS launches a process called JVM process. JVM initialises resources like memory and stuff like loading byte code into memory. And then it looks for main thread in the code and starts running that thread. Yes, When you run a program, the JVM process is created and the threads in your program run inside it.

  • @car_holic1995
    @car_holic1995 11 หลายเดือนก่อน +1

    If coder dont create threads exclusively..task is completed by only main thread?

  • @keshavdeosharma7222
    @keshavdeosharma7222 5 หลายเดือนก่อน +1

    Very nice explaination. Thank you Sir

  • @drissaitkassimusic
    @drissaitkassimusic 5 หลายเดือนก่อน +1

    You deserve more than million subs 👍👍👍👍👍

  • @amalamal3312
    @amalamal3312 5 หลายเดือนก่อน +1

    wow .just amazing

  • @AkashGupta-jb7zj
    @AkashGupta-jb7zj 7 หลายเดือนก่อน +1

    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!!

  • @siddhantprakash.
    @siddhantprakash. 5 หลายเดือนก่อน +1

    maza aaya kaafi din baad kuch padh ke.
    #Day4 of 7Days of java

  • @techmind9608
    @techmind9608 14 วันที่ผ่านมา

    Hi brother, i have bought membership but still unable to watch videos, there is note that says, you need membership, but i am already member, i bought it a day ago

    • @ConceptandCoding
      @ConceptandCoding  14 วันที่ผ่านมา

      kindly check the membership level pls

  • @stepswithvishnu2924
    @stepswithvishnu2924 9 หลายเดือนก่อน +7

    Worth to have your channel's membership. Nicely explained.

  • @rajneeshyadav3444
    @rajneeshyadav3444 2 หลายเดือนก่อน +4

    I believe even the creator of Java couldn't explain it better than you did.

  • @ashutoshsinghyadav5412
    @ashutoshsinghyadav5412 24 วันที่ผ่านมา

    faad diya
    Nice investment by me on myself

  • @rishiraj2548
    @rishiraj2548 หลายเดือนก่อน

    🤘

  • @krishnendughosh2368
    @krishnendughosh2368 10 หลายเดือนก่อน

    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?

  • @pleasantdayNwisdom
    @pleasantdayNwisdom 9 หลายเดือนก่อน

    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

  • @Randomvideo2610
    @Randomvideo2610 11 หลายเดือนก่อน +1

    what happens for api call it create separates process for each api call and allocates heap memory.

    • @jayendrasingh9260
      @jayendrasingh9260 11 หลายเดือนก่อน

      Each api calls his handle by spring internal threads

  • @imrohan97
    @imrohan97 6 หลายเดือนก่อน

    A 19:11, how does it get decided that how much Total JVM Heap Memory will be allocated

    • @imrohan97
      @imrohan97 6 หลายเดือนก่อน

      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?

  • @asharya5311
    @asharya5311 5 หลายเดือนก่อน

    @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.

  • @Ashish-hr3zn
    @Ashish-hr3zn 5 หลายเดือนก่อน

    Bit a MIxture of Compiler , Os , Computer Architechture ,nice video

  • @saurbhbansal7408
    @saurbhbansal7408 4 หลายเดือนก่อน

    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.

  • @atulvidyarthi9952
    @atulvidyarthi9952 3 หลายเดือนก่อน

    Where is metaspace in this?

  • @karmicveda9648
    @karmicveda9648 11 หลายเดือนก่อน +1

    🙌

  • @vaibhavjain1124
    @vaibhavjain1124 8 หลายเดือนก่อน

    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.

  • @yogendrasingh-nz3pw
    @yogendrasingh-nz3pw 3 หลายเดือนก่อน

    Thanks a lot for this wonderful knowledge sharing. Can someone please tell where is the remaining videos for multithreading part 2

  • @nikhilkumar3124
    @nikhilkumar3124 11 หลายเดือนก่อน +2

    Good videos. Cleared lot of doubts.

  • @kent.johnson
    @kent.johnson 5 หลายเดือนก่อน +1

    Nice

  • @aashiarora3150
    @aashiarora3150 9 หลายเดือนก่อน

    @Concept_&&_Coding How does JVM know how many threads it requires to execute a program?

  • @garvitjain9933
    @garvitjain9933 5 หลายเดือนก่อน

    Does JIT create all the required threads before running a process? Refer to the video at 32:30. This seems counter intutive

  • @lakshmanankanthi7158
    @lakshmanankanthi7158 9 หลายเดือนก่อน

    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

  • @umairalvi7382
    @umairalvi7382 3 หลายเดือนก่อน

    Why does it never happen that multiple threads execute the same statement multiple times how is it distributed among threads??

  • @theunusual4566
    @theunusual4566 9 หลายเดือนก่อน +1

    Thank you.

  • @kamalrai286
    @kamalrai286 3 หลายเดือนก่อน

    If there is one CPU and one register so how is it possible for thread having their individual registers

  • @Sushil2874
    @Sushil2874 11 หลายเดือนก่อน +1

    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!

  • @adityagupta375
    @adityagupta375 8 หลายเดือนก่อน

    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  8 หลายเดือนก่อน

      thanks. Many with experience in would say Aditya. Its been 8yrs and still working with Java tech stack only

  • @kritisingh1347
    @kritisingh1347 6 หลายเดือนก่อน +1

    thanks shreyansh

  • @ruthvikreddy1625
    @ruthvikreddy1625 8 หลายเดือนก่อน

    why is thread the smallest sequence of instruction? What does smallest here refer to?

  • @balakrushnabehera1631
    @balakrushnabehera1631 7 หลายเดือนก่อน

    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

  • @Krishna-iu4zp
    @Krishna-iu4zp 6 หลายเดือนก่อน

    context swithing is b/w processes or b/w thread or both ? (47:08)

  • @abc-ym4zs
    @abc-ym4zs 11 หลายเดือนก่อน

    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

  • @mehnaazmohiuddin
    @mehnaazmohiuddin 11 หลายเดือนก่อน +1

    you are doing a great job. Keep it up

    • @mehnaazmohiuddin
      @mehnaazmohiuddin 11 หลายเดือนก่อน

      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

  • @kaushikghosh8406
    @kaushikghosh8406 9 หลายเดือนก่อน

    What algorithm does this context switching follow? FIFO? Shortest job? Round robin?

    • @ConceptandCoding
      @ConceptandCoding  9 หลายเดือนก่อน

      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.

  • @nishantkumar6116
    @nishantkumar6116 8 หลายเดือนก่อน

    Nice Explanation...please create videos on Aspect Oriented Programming, I've got several question from AOP and spring AOP in my recent interviews

  • @nirajosh
    @nirajosh 9 หลายเดือนก่อน

    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  9 หลายเดือนก่อน

      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.

  • @mithunvasisht3176
    @mithunvasisht3176 11 หลายเดือนก่อน

    @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

  • @chhitijsrivastava793
    @chhitijsrivastava793 3 หลายเดือนก่อน

    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 ❣

  • @JaiChandraSekarRK
    @JaiChandraSekarRK 6 หลายเดือนก่อน

    brilliant explanation, thoroughly enjoyed it...where can i find part 2 and so on?

    • @ConceptandCoding
      @ConceptandCoding  6 หลายเดือนก่อน

      check the playlist 30th no video is part 2

  • @ManjeetKaur-y1y
    @ManjeetKaur-y1y 8 หลายเดือนก่อน

    @Shreyansh Great Explained but where is part 2 video?

    • @ConceptandCoding
      @ConceptandCoding  8 หลายเดือนก่อน

      already uploaded buddy 7-8 parts are there all uploaded

  • @LaptopBackup-bo6kp
    @LaptopBackup-bo6kp 9 หลายเดือนก่อน

    Is data segment alias for metaspace?

  • @Shadabkhan-tz7uv
    @Shadabkhan-tz7uv 3 หลายเดือนก่อน

    Who is bro?💀🙌

  • @jayendrasingh9260
    @jayendrasingh9260 11 หลายเดือนก่อน +1

    One of the best 👍

  • @nitishchaudhary7777
    @nitishchaudhary7777 7 หลายเดือนก่อน

    Bro, unable to find part 2, is that uploaded/created?

  • @gauravraj2604
    @gauravraj2604 10 หลายเดือนก่อน

    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  10 หลายเดือนก่อน +1

      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 9 หลายเดือนก่อน

      @@ConceptandCoding thank you for your response . Please do let me know the command.

  • @gauravraj2604
    @gauravraj2604 10 หลายเดือนก่อน

    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 10 หลายเดือนก่อน +1

      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  10 หลายเดือนก่อน

      @@gauravraj2604 yes

    • @gauravraj2604
      @gauravraj2604 10 หลายเดือนก่อน

      @@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?

  • @sargamgoyal4161
    @sargamgoyal4161 11 หลายเดือนก่อน

    Please make video on lambda functions also.

    • @ConceptandCoding
      @ConceptandCoding  11 หลายเดือนก่อน

      It's already there, pls check previous videos in Java playlist buddy

  • @zaheerabass7955
    @zaheerabass7955 11 หลายเดือนก่อน

    Point to point brings very much clearity. Thank You

  • @car_holic1995
    @car_holic1995 11 หลายเดือนก่อน

    Please include coding also bhai..

    • @ConceptandCoding
      @ConceptandCoding  11 หลายเดือนก่อน

      I will, this is fundamental video, what is process and thread. Thread creation will go next with coding buddy