Thread Life cycle
3) Running state
4) Blocked / waiting / non-running mode
5) Dead state
Second approach to create thread implementing Runnable interface:-
Creates a class that implements Runnable interface.
class MyClass extends Runnable
public void run()
System.out.println("body of the thread");
Creating a object.
MyClass obj=new MyClass();
Creates a Thread class object.
Thread t=new Thread(obj);
Starts the execution of a thread.
the Class MyClass implements the Runnable interface and overriding run() method and contains the logic associates with the body of the thread.
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.
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.