•We can suspend, resume and stop threads whenever we want. The way of suspending, resuming and stopping a thread has been changed since version 1.0 and in modern versions beginning with Java 2.
•In version 1.1 and prior to this version three methods were available in the Thread class. They are:
1) final void suspend() – To suspend the thread
2) final void resume() – To resume the thread
3) final void stop() – To terminate the thread
•In Java 2 the suspend() thread was deprecated as it may cause serious problems like deadlocks.
•Since suspend() method is deprecated, without it resume() method cannot be used.
•The stop() method is also deprecated as using it may lead to serious system failures like incomplete updates.
•So all the three methods suspend(), resume() and stop() must not be used in your programs.
•How to come around this problem?
•The solution is to use a flag variable and make the run() method check this flag variable.
•If the variable’s value is “suspend”, the thread will be suspended.
•If the variable’s value is “resume”, the thread will be resumed.
•In version 1.1 and prior to this version three methods were available in the Thread class. They are:
1) final void suspend() – To suspend the thread
2) final void resume() – To resume the thread
3) final void stop() – To terminate the thread
•In Java 2 the suspend() thread was deprecated as it may cause serious problems like deadlocks.
•Since suspend() method is deprecated, without it resume() method cannot be used.
•The stop() method is also deprecated as using it may lead to serious system failures like incomplete updates.
•So all the three methods suspend(), resume() and stop() must not be used in your programs.
•How to come around this problem?
•The solution is to use a flag variable and make the run() method check this flag variable.
•If the variable’s value is “suspend”, the thread will be suspended.
•If the variable’s value is “resume”, the thread will be resumed.
No comments:
Post a Comment