Java Threads - online test
1) The life cycle of the thread is controlled by ?
A) JVM
B) JDK
C) JRE
D) None of the above
View Answer / Hide Answer2) In how many states Threads can be explained ?
A) 4
B) 5
C) 3
D) 2
View Answer / Hide Answer3) In which state the thread is still alive, but is currently not eligible to run?
A) Non-Runnable
B) Terminated
C) Runnable
D) Running
View Answer / Hide Answer4) In Which state after invocation of start() method, but the thread Scheduler has not selected it to be the running thread?
A) Running
B) Runnable
C) Terminated
D) Non-Runnable
View Answer / Hide Answer5) These two ways are used to?
By extending Thread class
By implementing Runnable interface.
A) Joining a thread
B) Naming a thread
C) Create a thread
D) sleeping a thread
View Answer / Hide AnswerANSWER: C) Create a thread
6) Which method is used in thread class to starts the execution of the thread.JVM calls the run() method on the thread?
A) public void start()
B) public void run()
C) public void stop()
D) public coid suspend()
View Answer / Hide AnswerANSWER: A) public void start()
7) Which method is used in thread class to tests if the current thread has been interrupted?
A) public static boolean interrupted()
B) public boolean isInterrupted()
C) public void interrupt()
D) public boolean isAlive()
View Answer / Hide AnswerANSWER: A) public static boolean interrupted()
8) Which method in thread class causes the currently executing thread object to temporarily pause and allow other threads to execute?
A) public boolean isAlive()
B) public int getId()
C) public void yield()
D) public boolean isDaemon()
View Answer / Hide AnswerANSWER: C) public void yield()
9) Thread class constructor allocates a new thread object?
A) True
B) False
View Answer / Hide Answer10) Many threads at a time can run in a single process?
A) True
B) False
View Answer / Hide Answer11) Under Which scheduling the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence?
A) Under time slicing
B) Under Preemptive scheduling
C) Under Pretime slicing
D) None of the above
View Answer / Hide AnswerANSWER: B) Under Preemptive scheduling
12) How many methods does a thread class provides for sleeping a thread?
A) 3
B) 1
C) 4
D) 2
View Answer / Hide Answer13) Can we start a thread twice?
A) Yes
B) No
View Answer / Hide Answer14) What if we call run() method directly instead start() method?
A) Each thread starts in a separate call stack.
B) Invoking the run() method from main thread, the run() method goes onto the current call stack rather than at the beginning of a new call stack
C) Both A & B
D) None of the above
View Answer / Hide Answer15) Which method waits for a thread to die?
A) stop()
B) start()
C) terminate()
D) join()
View Answer / Hide Answer16) Which method returns a reference to the currently executing thread object?
A) currentThread()
B) runningThread()
C) runnableThread()
D) None of the above
View Answer / Hide AnswerANSWER: A) currentThread()
17) In Naming a thread which method is used to change the name of a thread?
A) public String getName()
B) public void setName(String name).
C) public void getName()
D) public String setName(String name)
View Answer / Hide AnswerANSWER: B) public void setName(String name)
18) Default priority value of a thread class for NORM_PRIORITY is?
A) 1
B) 10
C) 5
D) 4
View Answer / Hide Answer19) This is an example for priority of a thread give the output for the following program ?
class Multi10 extends Thread{
public void run(){
System.out.println("running thread name is:"+Thread.currentThread().getName());
System.out.println("running thread priority is:"+Thread.currentThread().getPriority());
}
public static void main(String args[]){
Multi10 m1=new Multi10();
Multi10 m2=new Multi10();
m1.setPriority(Thread.MIN_PRIORITY);
m2.setPriority(Thread.MAX_PRIORITY);
m1.start();
m2.start();
}
}
A) running thread name is:Thread-0
running thread priority is:1
running thread name is:Thread-1
running thread priority is:5
B) running thread name is:Thread-0
running thread priority is:10
running thread name is:Thread-1
running thread priority is:1
C) running thread name is:Thread-0
running thread priority is:5
running thread name is:Thread-1
running thread priority is:1
D) None of the above
View Answer / Hide Answer20) Daemon thread provides services to user threads for background supporting tasks,It has no role in life than to serve user threads?
A) True
B) False
View Answer / Hide Answer21) If you want to make a user thread as Daemon, it must not be started otherwise it will throw IllegalThreadStateException?
A) True
B) False
View Answer / Hide Answer22) In which Thread pool is used where container creates a thread pool to process the request?
A) Servlet
B) JSp
C) Both A & B
D) None of the above
View Answer / Hide Answer23) Which is the capability of control the access of multiple threads to any shared resource?
A) Serialization
B) Synchronization
C) Internationalization
D) None of the above
View Answer / Hide AnswerANSWER: B) Synchronization
24) Mutual exclusive and inter-thread communication are two types of Synchorization for ?
A) Thread Synchronization
B) Process Synchronization
C) Object Synchronization
D) None of the above
View Answer / Hide AnswerANSWER: A) Thread Synchronization
25) Which helps to keep threads from interfering with one another while sharing data. This can be done by three ways in java:
1.by synchronized method
2.by synchronized block
3.by static synchronization
A) Inter-thread communication
B) Mutual Exclusive
C) Initial-thread communication
D) None of the above
View Answer / Hide AnswerANSWER: B) Mutual Exclusive
26) The following two methods in Synchronization block is correct or not?
Synchronized block is not used to lock an object for any shared resource.
Scope of synchronized block is larger than the method.
A) True
B) False
View Answer / Hide Answer27) If you make any static method as synchronized, the lock will be on the?
A) class not on object
B) object
C) class
D) object not on class
View Answer / Hide AnswerANSWER: A) class not on object
28) Both threads are waiting for each other to release the lock, the condition is called deadlock?
A) True
B) False
View Answer / Hide Answer29) In which mechanism a thread is paused running in its critical section and another thread is allowed to enter (or lock) in the same critical section to be executed?
A) Inter-thread communication
B) Initial-thread communication
C) Mutual Exclusive
D) None of the above
View Answer / Hide AnswerANSWER: A) Inter-thread communication
30) In inter-thread communication in java the following method is used for public final void wait(long timeout)throws InterruptedException?
A) waits until object is notified
B) waits for the specified amount of time
C) waits until object is released
D) None of the above
View Answer / Hide AnswerANSWER: B) waits for the specified amount of time
31) Which method returns the interrupted flag afterthat it sets the flag to false if it is true?
A) isInterrupted()
B) static interrupted()
C) non static interrupted()
D) Both A & C
View Answer / Hide AnswerANSWER: B) static interrupted()
32) In Reentrant Monitor It eliminates the possibility of single thread deadlocking?
A) True
B) False
View Answer / Hide Answer