Arjun:
We can interrupt a thread using the interrupt method right? is there any way we can interrupt a thread other than this when it's sleeping or waiting or if a thread is on a join operation?
I think i did not understand this.
Are you asking: Are Sleep/wait/join broken by interrupt?
If yes, then the answer is Yes!
If a thread is sleeping/waiting/join, it will respond to interrupt.
(If you notice, all the methods throw an InterruptedException)
In addition to this, if a thread is blocked on I/O, there are two possibilities:
1) Thread is using channels that are Interruptable(From the nio library). In such cases, the thread will respond to interrupt.
2) Thread is using traditional I/O classes like Streams, then the thread does not respond to interrupt. However, the interrupt status is set in the thread and any class that checks this status(eg: wait checks this status before getting into wait), will throw an InterruptedException.
Now, if you are asking "any other way than interrupt", then there is none, but i dont think of a reason as to why you want it.
Arjun:
Also, stop,suspend,destroy methods have all been deprecated right? so is there a way we can actually kill a thread?
Nope.
You can only send a signal to the thread to stop i.e. a thread can be only co-operatively stopped!
If you search this forum you will find numerous posts that tell you ways to co-operatively stop a thread.