Public final void Stop (): Let the thread stop, obsolete, but can also be used.
public void Interrupt (): Middle break thread. Terminates the state of the thread and throws a interruptedexception.
1 Public classThreadstopdemo {2 Public Static voidMain (string[] args) {3Threadstop ts =Newthreadstop ();4 Ts.start ();5 6 //If you don't wake up in three seconds, I'll kill you.7 Try {8Thread.Sleep ( the);9 //ts.stop ();Ten ts.interrupt (); One}Catch(interruptedexception e) { A e.printstacktrace (); - } - } the } - Public classThreadstop extends Thread { - @Override - Public voidrun () { +System. out. println ("Start Execution:"+NewDate ()); - + //I'm going to take 10 seconds off, kiss, don't disturb me! A Try { atThread.Sleep (10000); -}Catch(interruptedexception e) { - //e.printstacktrace (); -System. out. println ("the thread is terminated."); - } - inSystem. out. println ("End Execution:"+NewDate ()); - } to}
Java Note thread Mode 1 thread terminal and stop