Wednesday, May 4, 2011

yield(), join() and daemon thread

Yield():-
It is a static method in the thread class. When the yield() is called then the thread will be moved to runnable state from the running state and it will give chance to execute another thread with lowest priority (current thread).

Join():-
When you are calling join() then the current executing thread will be moved to waiting state and it will be re-executed after completing the thread on which the join method is called. This method may throw Interrupted Exception.

Daemon Thread:-
It is a special type of thread that will be used to provide the service for main thread. It will be executed till main thread is executing. After completing the main thread there is no guarantee that the daemon thread will be completed successfully. If you want to verify whether one thread is daemon thread or not then you can use the following method.
public final boolean is Daemon();
If you want to define one thread as daemon thread then you can call the following method with the thread object.

No comments:

Post a Comment