Wednesday, May 7, 2008

Java Interview Questions 35

171. How to create multithread in a program?
Answer: You have two ways to do so. First, making your class "extends" Thread
class. Second, making your class "implements" Runnable interface. Put jobs in a
run() method and call start() method to start the thread.

172. Can Java object be locked down for exclusive use by a given
thread?
Answer: Yes. You can lock an object by putting it in a "synchronized" block. The
locked object is inaccessible to any thread other than the one that explicitly
claimed it

173. Can each Java object keep track of all the threads that want to
exclusively access to it?
Answer: Yes

174. What state does a thread enter when it terminates its processing?
Answer: When a thread terminates its processing, it enters the dead state.

175. What invokes a thread's run() method?
Answer: After a thread is started, via its start() method of the Thread class, the
JVM invokes the thread's run() method when the thread is initially executed.

No comments:

Useful Information