Suspend or resume method:
Since you can't use the suspend ( ) resume ( ), or stop ( ) methods in Java 2 to control a thread, you may be thinking in which no way exists to pause, restart, or terminate a thread. But, fortunately, this is not true. Alternatively, a threads must be designed so in which the run( ) method periodically checks to determine whether that thread should suspend, resume, or stop its own execution. Classically, this is accomplished through establishing a flag variable which denotes the execution state of the thread. As long as this flag is set to "running", the run ( ) method must continue to let the thread execute. The thread must pause if this variable is set to "suspend". If it is set to "stop", the thread must terminate. Of course, a variety, of ways exists in that to write such code, but the central theme will be the similar for all programs.
The given example describes how the wait ( ) and notify ( ) methods which are inherited from Object can be used to control the execution of a thread; this instance is same to the program in the previous section. Therefore, the deprecated methods calls have been removed. Consider the operation of this program.