Interrupt Learning for Java threads

Source: Internet
Author: User

<span style= "font-size:18px;" >package thread.java.test;/** * Practice here is the thread interrupt * THREAD.INTERRUPT () to set the interrupt state is true when one thread is running and another thread can invoke the interrupt of another * thread () method to interrupt him * THREAD.ISINTERRUPT () to get the interrupt state of the thread * thread.interrupted () This is a static method used to get the interrupt state, and to clear the interrupt state, * It gets the value before the purge, call two consecutive times, The second time will definitely return false * @author Hello * @version jdk1.8.45 * @since 2015-07-25 * */public class Sleepinterrupt implements Runnable { public void Run () {try {System.out.println ("in the Run () method-this thread sleeps for 10 seconds"); Thread.Sleep (10000); System.out.println ("In the Run () method-Continue running");} catch (Interruptedexception e) {e.printstacktrace ();} System.out.println ("In the Run () method--continue to complete after hibernation");       System.out.println ("In the Run () method-Normal Exit");} public static void Main (string[] args) {sleepinterrupt si=new sleepinterrupt (); Thread t=new thread (SI), T.start (), try {thread.sleep (),} catch (Interruptedexception e) {e.printstacktrace ();} System.out.println ("in the Main () method-interrupts other threads"); T.interrupt (); SYSTEM.OUT.PRINTLN ("in Main ()--Exit");}} </span> 

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Interrupt Learning for Java threads

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.