Java Thread Methods

The Thread class has methods that can be used to control the behaviour of threads. There are two constructors in thread class

    public Thread(String threadName)
    public Thread()

1. start() method

This method is used to start a new thread. When this method is called the thread enters the ready to run mode and this automatically invokes the run( ) method .

void start( )

2. run() method

This method is the important method in the thread and it contains the statements that are to be executed in our program. It should be overridden in our class, which is derived from Thread class.

void run( )

{

 //Statements implementing thread

}

3. sleep() method

This method is used to block the currently executing thread for the specific time.

void sleep(time in milliseconds )

4. interrupted() method

This method returns true if the thread has been interrupted

static boolean interrupted( )

5. isAlive() method

This method returns true if the thread is running.

boolean isAlive( )

6. stop() method

This method is used to stop the running thread.

void stop()

7. wait() method

This method is used to stop the currently executing thread until some event occurs

void wait()

8. yield() method

This method is used to bring the blocked thread to ready to run mode.

void yield()

9. setPriority( ) method

This method is used to set the priority of the thread.

void setPriority(int P)

10. getPriority( ) method

This method is used to get the priority of the thread.

int getPriority( )

Search:

Recent Posts