a. Process-based.b. Thread-based.
A thread is a single sequential flow of control within a program.
a.Extend the Thread class and override the run() method.b.Implement the Runnable interface and implement the run() method.
I will make ABC implement the Runnable interface to create a new thread, because ABC class will not be able to extend both XYZ class and Thread class.
Ready,Running,Waiting and Dead.
The thread support lies in java.lang.Thread, java.lang.Object and JVM.
notify() method moves a thread out of the waiting pool to ready state, but there is no guaranty which thread will be moved out of the pool.
When a Thread calls the sleep() method, it will return to its waiting state. When a Thread calls the yield() method, it returns to the ready state.
Daemon is a low priority thread which runs in the backgrouund.
We should call setDaemon(true) method on the thread object to make a thread as daemon thread.
Normal threads do mainstream activity, whereas daemon threads are used low priority work. Hence daemon threads are also stopped when there are no normal threads.
Garbage Collector is a low priority daemon thread.
The thread's start() method puts the thread in ready state and makes the thread eligible to run. start() method automatically calls the run () method.
a. Method can be declared as synchronised.b. A block of code be sychronised.
Yes, we can declare static method as synchronized. But the calling thread should acquire lock on the class that owns the method.
A thread can execute it's own run() method or another objects run() method.
A condition that occurs when two processes are waiting for each other to complete before proceeding. The result is that both processes wait endlessly.
a. wait(),notify() & notifyall()b. Object class
Its not possible. A monitor can be held by only one thread at a time.
500 is the no of milliseconds and the data type is long.
False. A block of code can also be synchronised.
A monitor is an object which contains some synchronized code in it.
only run() method is defined the Runnable interface.
A dead Thread cannot be started again.
A Thread dies after completion of run() method.
The yield() method puts currently running thread in to ready state.
The java.lang.Object class wait() method throws "InterruptedException".
notifyAll() method moves all waiting threads from the waiting pool to ready state.
wait() method releases CPU, releases objects lock, the thread enters into pool of waiting threads.