Curioustab
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Threads Questions
In core Java concurrency, which three of the following are methods declared by java.lang.Object (select exactly three)? notify() notifyAll() isInterrupted() synchronized() interrupt() wait(long msecs) sleep(long msecs) yield()
Java threads — starting a thread that implements Runnable. Given: class X implements Runnable { public static void main(String args[]) { // Which line starts a new thread correctly? } public void run() {} }
Threads — which three operations guarantee that the
current
thread will leave the running state? Choose exactly three: yield(), wait(), notify(), notifyAll(), sleep(1000), aLiveThread.join(), Thread.killThread()
Java Thread API — which two are valid constructors for java.lang.Thread?
Which of the following cannot directly cause a Java thread to stop executing (i.e., leave the running state) at the moment of the call?
Which two of the following methods are members of java.lang.Thread (not inherited from Object or declared elsewhere)?
Thread lifecycle — which method actually registers a new thread with the scheduler and starts it?
Runnable contract — which method signature must a class provide to correctly implement java.lang.Runnable?
Which of the following will NOT directly cause the calling thread to stop executing at that moment?
In Java, which type declares the monitor methods wait(), notify(), and notifyAll() that coordinate threads?
In Java multithreading, which method contains the actual body of work executed by a Thread (i.e., the code that runs on the thread's stack when scheduled by the JVM scheduler)?
Java concurrency: A thread A calls wait(2000) inside a synchronized method on object B. When does thread A become eligible (a candidate) to run again?
In Java, which method is used to start a thread's execution on a new call stack?
Java threads: Which of the following will directly cause a thread to cease executing (stop running) at that moment?
Which statement correctly creates a Java thread from a class that implements Runnable and starts it running?
What will be the output of the program? class Happy extends Thread { final StringBuffer sb1 = new StringBuffer(); final StringBuffer sb2 = new StringBuffer(); public static void main(String args[]) { final Happy h = new Happy(); new Thread() { public void run() { synchronized(this) { h.sb1.append("A"); h.sb2.append("B"); System.out.println(h.sb1); System.out.println(h.sb2); } } }.start(); new Thread() { public void run() { synchronized(this) { h.sb1.append("D"); h.sb2.append("C"); System.out.println(h.sb2); System.out.println(h.sb1); } } }.start(); } }
What will be the output of the program? class MyThread extends Thread { public static void main(String [] args) { MyThread t = new MyThread(); /* Line 5 */ t.run(); /* Line 6 */ } public void run() { for(int i=1; i < 3; ++i) { System.out.print(i + ".."); } } }
What will be the output of the program? public class Test107 implements Runnable { private int x; private int y; public static void main(String args[]) { Test107 that = new Test107(); (new Thread(that)).start(); (new Thread(that)).start(); } public synchronized void run() { for(int i = 0; i < 10; i++) { x++; y++; System.out.println("x = " + x + ", y = " + y); /* Line 17 */ } } }
What will be the output of the program? class MyThread extends Thread { MyThread() {} MyThread(Runnable r) {super(r); } public void run() { System.out.print("Inside Thread "); } } class MyRunnable implements Runnable { public void run() { System.out.print(" Inside Runnable"); } } class Test { public static void main(String[] args) { new MyThread().start(); new MyThread(new MyRunnable()).start(); } }
What will be the output of the program? class MyThread extends Thread { public static void main(String [] args) { MyThread t = new MyThread(); Thread x = new Thread(t); x.start(); /* Line 7 */ } public void run() { for(int i = 0; i < 3; ++i) { System.out.print(i + ".."); } } }
1
2