interrupt method in Thread Java
A thread can interrupt a sleeping or waiting thread by using interrupt() method of Thread class.
public void interrupt()
Ex:
Note ( Imp* )
- Whenever we are calling interrupt() method and if target Thread is not in sleeping state or waiting state, then there is no impact of interrupt call immediately.
- interrupt() call will be waited until target Thread entered into sleeping or waiting state.
- If the target thread entered into sleeping or waiting state, then immediately interrupt() call will interrupt the target thread.
- If the target thread never entered into sleeping or waiting state in the lifetime the, there is no impact of interrupt() call. This is only case where interrupt() call will be wasted.
Ex: