>

Friday, December 14, 2012

Threads Question And Answers

What is thread?
It is the unit of execution which doesn't have any existence.

What is Synchronization?
It is the controlling mechanism when multiple threads are trying to access same resource.

How can be a thread Created?
By extending thread class and implementing runnable interface.

What is the use of sleep method?
Sleep method is used to stop the execution of a thread temporarily for a user defined milliseconds.

What is Preemptive Scheduling?
When an lower priority thread is already running  that thread will be suspended and higher priority thread will get executed.

What is Time slicing?
It is the process where the time is sliced between equal priority threads.

What are the methods available in threads?
Thread t=new Thread();
t.getName()-To get the name of thread.
t.setName()-To set the name for thread.
t.getPriority()- To get the priority
t.setPriority()-To set the priority

constant properties of thread
MAX_PRIORITY=10
MIN_PRIORITY=1
NORM_PRIORITY=5

What are the states of an thread?
newborn()->runnable->running>dead.

What is Daemon Thread?

It is a thread which will be invoked by automatically without intervention of user. Garbage collector is example for Daemon Thread.

What is run Method?
Whether we use implement runnable or extending thread the public void run() method should be override. And using start() method we start running a thread.

No comments:

Post a Comment

Please post your comments. Your comments make us to write more programs for you.