Starting new thread: – A new thread can be creating and run and instance of our thread class. Before running a thread, we can create an object for thread class and it can be run using the start method. This method running the thread from very beginning. Syntax of the thread initialization is –

<Thread Name> <Object>=new <Thread Name>();
<Object>.start();

Here, first line initiates a new object of class declared as thread name. note that this statement just creates the object. The thread that will run this object is not yet running. This thread known as newborn state. The second line calls the start() method causing the thread to move into the runnable state. Then the java run time schedule the thread to run by invoking its run() method. Now the thread is said to be in the running state.

Advertisements