Multithreading


  1. What is the name of the thread in output of this program?
    public class multithreaded_Name
    {
    public static void main(String args[])
    {
    Thread thread = Thread.currentThread();
    thread.setName("First");
    System.out.println(thread);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    The output of program is Thread[First,5,main], Since we have not explicitly named the thread they are named by the group to they belong i:e main method. Hence they are named ‘main’.


  1. What is the priority of the thread in output of this program?
    public class multithreading_Priority 
    {
    public static void main(String args[])
    {
    Thread thread = Thread.currentThread();
    System.out.println(thread);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    The output of program is Thread[main,5,main], in this priority assigned to the thread is 5. It’s the default value. Since we have not named the thread they are named by the group to they belong i:e main method.



  1. What is the output of this program?
    public class multithreading_SimpleExample
    {
    public static void main(String args[])
    {
    Thread thread = Thread.currentThread();
    System.out.println(thread);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Thread[main,5,main]


  1. Which of these statements is incorrect?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Thread exist in several states, a thread can be running, suspended, blocked, terminated & ready to run.



  1. What will happen if two thread of the same priority are called to be processed simultaneously?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    In cases where two or more thread with same priority are competing for CPU cycles, different operating system handle this situation differently. Some execute them in time sliced manner some depending on the thread they call.