OOP Unit 9 Notes
OOP Unit 9 Notes
2. Daemon thread: Daemon threads are low priority threads that are
created to provide services to the user thread. These threads are only needed while user
threads are running and are meant to serve them. Unlike user threads it does’nt prevent
JVM from exiting once all user threads have finished their execution. These threads are
used to perform background tasks such as garbage collection ,removing unwanted
entries etc.
1. New.
2. Runnable.
3. Running.
4. Blocked(Non-Runnable).
5. Dead.
Diagram:
scheduler.
I/O operations.
The start() method internally calls the run() method of Runnable interface to execute the
code specified in the run() method in a separate thread.
The run() method can be called using the start() method or by calling the run() method
itself. But when you use run() method for calling itself, it creates problems.
class ST
}
//Thread Creation using interface
import java.util.*;
System.out.println("Thread Creation");
class ST
}
call the run() method more than one time
public class RunExp3 extends Thread
{
public void run()
{
for(int i=1;i<6;i++)
{
try
{
Thread.sleep(500);
}catch(InterruptedException e){System.out.println(e);}
System.out.println(i);
}
}
public static void main(String args[])
{
RunExp3 t1=new RunExp3();
RunExp3 t2=new RunExp3();
t1.run();
t2.run();
}
}