Java Note thread Mode 1 thread terminal and stop

Source: Internet
Author: User
Tags thread stop

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.