13.2 Multithreading in Java Practical

Java

Video is ready, Click Here to View ×


In computer science, a thread of execution is the smallest sequence of programmed instructions that can be managed independently by a scheduler, which is typically a part of the operating system.
Multithreading in java is a process of executing multiple activities can proceed concurrently in the same program.
Thread is basically a lightweight sub-process, a smallest unit of processing.
In multithreading threads share a common memory area.
They don’t allocate separate memory area so saves…

27 thoughts on “13.2 Multithreading in Java Practical

  1. What about if i have two for loops in the same class but in different methods that i want to run simultaneously? Do i have to put them in defferent classes to make it work?

  2. Shouldn't the "obj1.start()" execute first , whatever inside it is, and then the control flow will move to "obj2.start()". Does the flow comes to "obj2.start()" before completing the method "obj1.start()" ?

  3. if i keep the try catch(i mean the sleep part) out of the for loop, for both the classes (hi & hello) then we will not get alternative hi and hello in the display(output) window. then we will get 5 hi and 5 hello(not alternatively). WHY??

  4. //its not working bro…………………………….ERROR:CANT IMPLEMENT run() in runnable……………………
    class hello extends Thread{
    void run(){
    for(int i=1;i<=5;i++)
    System.out.println("hello");
    try{Thread.sleep(1000);}catch(Exception e){}
    }
    }
    class Hi {
    void run(){
    for(int i=1;i<=5;i++)
    System.out.println("hi");
    try{Thread.sleep(1000);}catch(Exception e){}
    }
    }
    class threaddemo{
    static void main(){
    Hi obj=new Hi();
    hello obj2=new hello();
    obj.run();
    obj2.run();
    }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *