/* related posts with thumb nails */

Starting, Stopping and Blocking threads:

Starting a thread:

When we create a thread by taking instance of a thread class, the thread will be in its new-born state. To move it to runnable state, we use a method named start( ). When we invoke this method with a thread, java run-time schedules it to run by invoking it run() method. Now the thread will be in its running state. To start a thread we use the following syntax:

MyThread t1 = new MyThread();


Stopping a thread:

Whenever we want to stop a thread from running further, we may do so by calling its stop() method. This causes a thread to stop immediately and move it to its dead state. It forces the thread to stop abruptly before its completion i.e. it causes premature death. To stop a thread we use the following syntax:


Blocking a Thread:

A thread can also be temporarily suspended or blocked from entering into the runnable and subsequently running state by using either of the following thread methods:

sleep(t) // blocked for ‘t’ milliseconds

suspend() // blocked until resume() method is invoked

wait() // blocked until notify () is invoked

These methods cause the thread to go into the blocked (or not-runnable) state. The thread will return to the runnable state when the specified time is elapsed in the case of sleep( ), the resume() method is invoked in the case of suspend( ), and the notify( ) method is called in the case of wait().

Related Topics:


Unknown said...


Swetha said...


Unknown said...

One of the best

Vishnu singh chouhan said...

Super, innovative and mind blowing

BITA Academy said...

Best tutorial. You have written impressive tutorials on Java. I am glad to come across this. As a company providing Best Java Training Institute in Chennai, I am very grateful to come across this. After reading it , I think that you have good knowledge. Thanks for posting it. Keep it up.

Technical Treat said...

great explanation!

Post a Comment