Methods | Description |
---|---|
public void start( ) | This method invokes the run() method, which causes the thread to begin its execution. |
public void run( ) | Contains the actual functionality of a thread and is usually invoked by start() method. |
public static void sleep (long millisec) | Blocks currently running thread for at least certain millisecond. |
public static void yield ( ) | Causes the current running thread to halt temporarily and allow other threads to execute. |
public static Thread currentThread ( ) | It returns the reference to the current running thread object. |
public final void setPriority (int priority) | Changes the priority of the current thread. The minimum priority number is 1 and the maximum priority number is 10. |
public final void join (long millisec) | Allows one thread to wait for completion of another thread. |
public final boolean isAlive ( ) | Used to know whether a thread is live or not. It returns true if the thread is alive. A thread is said to be alive if it has been started but has not yet died. |
public void interrupt ( ) | Interrupts the thread, causing it to continue execution if it was blocked for some reason. |
public class DaemonThreadDemo extends Thread
{
public void run()
{
if(Thread.currentThread().isDaemon())
{
System.out.println("Daemon Thread");
}
else
{
System.out.println("User Thread");
}
}
public static void main(String[] args)
{
DaemonThreadDemo t1 = new DaemonThreadDemo();
DaemonThreadDemo t2 = new DaemonThreadDemo();
DaemonThreadDemo t3 = new DaemonThreadDemo();
t1.setDaemon(true);
t1.start();
t2.start();
t3.start();
}
}