Suspending, Resuming and Stopping Threads in Java

The functions of Suspend, Resume and Stop a thread is performed using Boolean-type flags in a multithreading program. These flags are used to store the current status of the thread.

1. If the suspend flag is set to true then run() will suspend the execution of the currently running thread.

2. If the resume flag is set to true then run() will resume the execution of the suspended thread.

3. If the stop flag is set to true then a thread will get terminated.

Program:

 

Output:
Suspending, Resuming and Stopping Threads in Java

Thead Priority:

In Java, each thread is assigned a priority which affects the order in which it is scheduled for running. The threads are of the same priority by the Java Scheduler and therefore they share the processor on a First-Come-First-Serve basis.
Java permits us to set the priority of a thread using the setPriority() as follows:

Where intNumber is an integer value to which the thread’s priority is set. The Thread class defines several priority constants:

MIN_PRIORITY = 1
NORM_PRIORITY = 5
MAX_PRIORITY = 10