Menu
Topics Index
...
`

Thread Set Priority


If you need explanation Read this topic

If you need Answer Take test on this topic

Thread Set Priority
What will be the output of the following program?
public class WorkingWithThread extends Thread {
    String str = "";
    public WorkingWithThread(String s) {    str = s;    }
    public void run() {
        if (str.equals("thread1") | str.equals("thread2")) {
            yield();
            System.out.println("End of " + str);
        }
    }
    public static void main(String args[]) {
        Thread thread1 = new WorkingWithThread("thread1");
        Thread thread2 = new WorkingWithThread("thread2");
        thread2.setPriority(Thread.MAX_PRIORITY);
        thread1.setPriority(Thread.MIN_PRIORITY);
        thread1.run();
        thread2.run();
    }
}

A. End of thread1
End of thread2
B. End of thread2
End of thread1
C. Some other output
D. Output can not be determined
E. Compilation Error or Runtime Error
Topic: What is Multitasking and Multithreading?

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

answer is:  A

Posted by Dinesh Namburi    2014-03-14 09:02:02


ans is A,because here we are explicitly calling the run() method in the thread.

Posted by Raviteja Daggupati    2014-03-14 09:12:13


answer is [A] as thread2 priority is higher then thread1 the yield() method will pause the thread1 and give thread2 chance to execute .

Posted by Ashok Kumar Paritala    2014-03-14 09:12:55


A

Posted by Gopinath Manchikanti    2014-03-15 08:34:04


Congratulations Ashok Kumar Paritala. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-03-17 04:25:04


© meritcampus 2019

All Rights Reserved.

Open In App