Explain how to Stop and Block a Thread?


Stopping a thread:

whenever we want to stop a thread from running further, we call stop() method.

x.stop( );

This statement causes the thread to move to the dead state. A thread will also move to the dead state automatically when it reaches the end of the method.

The stop( ) method may be used when the premature death of a thread is desired.

Blocking a thread :

A thread can also be temporarily suspended or blocked from entering in to the runnable and subsequently running state by using either of the following thread methods.
.
sleep( )®blocked for a specified time

suspend ( )®blocked until further orders.

wait( )®blocked until certain condition occurs.

These methods cause the thread to go into the blocked (or not runnable ) state.

The thread will return to the runnable state when the specified time is elapsed in the case of sleep( ),

The resume( ) is involved in the case of suspend( ) and

notify( ) is called case of wait( ).


Related

Java 4867802679858865472

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item