41. What is the difference between pre-emptive multi-tasking and co-operative multi-tasking?
In case of pre-emptive multitasking, the program is interrupted without consulting first where as in case of co-operative multitasking; programs are interrupted only when they are willing to yield control.
Windows 95,NT – pre-emptive multi-tasking where Windows 3.1 is co-operative multitasking.
Pre-emptive multi-tasking is more effective as compared co-operative multitasking.
42. What is difference between creating a thread by extending Thread class and implementing Runnable?
Explain the four different states of a thread
The four different states of a thread are
New: When a thread is created with new operator .It is not yet running.
Runnable: Once you invoke the start method on the thread it becomes runnable. It is up to the OS to decide when to give time to the thread to run. A runnable thread may or may not be running.
Blocked : Thread enters this state under the following condition.
Someone calls sleep () on the thread.
Thread calls an operation that blocks on input/output.
Thread calls wait() method.
Thread tries to lock an object that is currently locked by another thread.
Dead : The Thread is dead for one of two reasons.
It dies a natural death because the run method exits normally.
It dies abruptly because an uncaught exception terminates the run method.
43. What happens when there are more than one highest priority threads having same priority?
In that case only one of the thread is picked up. It is up to the thread Scheduler to arbitrate between threads of same priority.
There is no guarantee that all the same priority threads will be fairly treated.
44. Why do threads block on I/O ?
Threads block on I/O so that other threads may execute while the I/O operation is performed.
45. What are the methods which can only be called from within a Synchronized method or block ?
Notify (): unblocks one randomly selected thread among the threads that called wait() on this object.
NoitifyAll() : unblocks the threads that called wait() on this object.
Wait (): causes the thread to wait until it is notified.
46. What is the difference between yield and sleep methods of Thread?
When a task invokes its yield () method, it returns to the ready state. When a task invokes its sleep () method, it returns to the waiting state.
About Me
Sunday, March 30, 2008
CORE JAVA FAQS
Posted by Its For Techies at 1:00 AM
Labels: CORE JAVA faqs-9
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment