Thread Life cycle
1) New
2) Ready
3) Running state
4) Blocked / waiting / non-running mode
5) Dead state
Java Images
Second approach to create thread implementing Runnable interface:-
Step 1:-
Creates a class that implements Runnable interface.
class MyClass extends Runnable
public void run()
System.out.println("body of the thread");
Step 2:-
Creating a object.
MyClass obj=new MyClass();
Step 3:-
Creates a Thread class object.
Thread t=new Thread(obj);
Step 4:-
Starts the execution of a thread.
Step 1:-
the Class MyClass implements the Runnable interface and overriding run() method and contains the logic associates with the body of the thread.
Step 2:-
Creates the object of implementation class this is not like a first mechanism.
Step 3 :-
Creates a generic thread object then pass the MyClass reference variable as a parameter to that object.
Step 4:-
As a result of third step 3 a thread object is created in order to execute this thread method we need to class start() method. Then new thread is executed.