Q301.If
a waiting thread got notification then it will entered into which state?
Ans. It will entered into another waiting state to get lock.
Q302.In which method threads can release the lock?
Ans. Once a Thread calls wait() method it immediately releases the lock of that object and then entered into waiting state similarly after calling notify() method Thread releases the lock but may not immediately. Except these three methods( wait(), notify(), notifyAll() ) method Thread neverreleases the lock anywhere else.
Q303. Explain wait(), notify(), notifyAll() method uses.
Ans. Two Threads will communicate with each other by using wait(), notify() or notifyAll() methods.
These methods are defined in Object class but not in Thread because Threads are calling this method.
Q304. What is the difference between notify() and notifyAll()?
Ans. To give notification to the single waiting Thread. We use notify() method and to give notification to all waiting thread we use notifyAll() method.
Q305. Once a Thread got the notification then which waiting thread will get chance?
Ans. It is depends on the Thread Scheduler.
Q306. How a thread can interrupt another thread?
Ans. A Thread can interrupt another Thread by using interrupt() method.
Q307. Which keyword causes DeadLock situation?
Ans. Synchronized keyword is the thing to causes of DeadLock. If we are not using properly synchronized keyword the program will entered into DeadLock situation.
Q308. How we can stop a thread explacitly?
Ans. Thread class defines stop() method by using this method we can stop a Thread. But it is deprecated. And hence not recommended to use.
Q309. Explain about suspend() and resume() method?
Ans. A Thread can suspend another Thread by using suspend() method.
A Thread can resume a suspended Thread by using resume() method.
Q310.What is Starvation()? And Explain the difference between Deadlock and Starvation?
Ans. A long waiting Thread is said to be in starvation (because of least priority) but after certain time defiantly it will get the chance for execution. But in the case of Deadlock two Threads will wait for each other forever. It will never get the chance for execution.
Ans. It will entered into another waiting state to get lock.
Q302.In which method threads can release the lock?
Ans. Once a Thread calls wait() method it immediately releases the lock of that object and then entered into waiting state similarly after calling notify() method Thread releases the lock but may not immediately. Except these three methods( wait(), notify(), notifyAll() ) method Thread neverreleases the lock anywhere else.
Q303. Explain wait(), notify(), notifyAll() method uses.
Ans. Two Threads will communicate with each other by using wait(), notify() or notifyAll() methods.
These methods are defined in Object class but not in Thread because Threads are calling this method.
Q304. What is the difference between notify() and notifyAll()?
Ans. To give notification to the single waiting Thread. We use notify() method and to give notification to all waiting thread we use notifyAll() method.
Q305. Once a Thread got the notification then which waiting thread will get chance?
Ans. It is depends on the Thread Scheduler.
Q306. How a thread can interrupt another thread?
Ans. A Thread can interrupt another Thread by using interrupt() method.
Q307. Which keyword causes DeadLock situation?
Ans. Synchronized keyword is the thing to causes of DeadLock. If we are not using properly synchronized keyword the program will entered into DeadLock situation.
Q308. How we can stop a thread explacitly?
Ans. Thread class defines stop() method by using this method we can stop a Thread. But it is deprecated. And hence not recommended to use.
Q309. Explain about suspend() and resume() method?
Ans. A Thread can suspend another Thread by using suspend() method.
A Thread can resume a suspended Thread by using resume() method.
Q310.What is Starvation()? And Explain the difference between Deadlock and Starvation?
Ans. A long waiting Thread is said to be in starvation (because of least priority) but after certain time defiantly it will get the chance for execution. But in the case of Deadlock two Threads will wait for each other forever. It will never get the chance for execution.
No comments:
Post a Comment