Suspending And Resuming Threads In Java
They have the following forms.
Suspending and resuming threads in java. Synchronized this while suspended wait. The suspend method is deprecated because when a thread which has lock is suspended it causes the other threads to wait. Syntax public final void suspend Return.
If the stop flag is set to true then a thread will get terminated. NewThreadString threadname name threadname. This function makes a thread temporarily cease execution.
TIlKY have the form shown below. Final void suspend final void resume The following program demonstrates these methods. This method is used if you want to stop the thread execution and start it again when a certain event occurs.
Synchronized void stop stopped true. If the resume flag is set to true then run will resume the execution of the suspended thread. Than Thread-2 will try to acquire lock on Stringclass and lock is available.
Systemoutprintln n thrdgetName exiting. Public void stop This method stops a thread completely. If that thread is suspended.
Catch InterruptedException exc Systemoutprintln thrdgetName interrupted. 5 seconds taken in this program is over and then we resume. Whatever the case it is a simple matter to suspend a thread.