当前位置: 首页 > news >正文

福建有没有网站做鞋子一件代发自己如何制作网页

福建有没有网站做鞋子一件代发,自己如何制作网页,中国采购与招标网官方网站,免费门户网站源码文章目录 暂停中断**阻塞情况下中断,抛出异常后线程恢复非中断状态,即 interrupted false**调用Thread.interrupted() 方法后线程恢复非中断状态 暂停 Java中线程的暂停是调用 java.lang.Thread 类的 sleep 方法。该方法会使当前正在执行的线程暂停指定…

文章目录

    • 暂停
    • 中断
      • **阻塞情况下中断,抛出异常后线程恢复非中断状态,即 interrupted = false**
      • 调用Thread.interrupted() 方法后线程恢复非中断状态

暂停

Java中线程的暂停是调用 java.lang.Thread 类的 sleep 方法。该方法会使当前正在执行的线程暂停指定的一段时间,如果线程持有锁, sleep 方法结束前并不会释放该锁。

中断

java.lang.Thread类有一个 interrupt 方法,该方法直接对线程调用。当被interrupt的线程正在sleep或wait时,会抛出 InterruptedException 异常。
事实上, interrupt 方法只是改变目标线程的中断状态(interrupt status),而那些会抛出InterruptedException 异常的方法,如wait、sleep、join等,都是在方法内部不断地检查中断状态的值。

  • interrupt方法

Thread实例方法:必须由其它线程获取被调用线程的实例后,进行调用。实际上,只是改变了被调用线程的内部中断状态;
源码

    public void interrupt() {if (this != Thread.currentThread())checkAccess();synchronized (blockerLock) {Interruptible b = blocker;if (b != null) {interrupt0();           // Just to set the interrupt flagb.interrupt(this);return;}}interrupt0();}
  • Thread.interrupted方法
    Thread类方法:必须在当前执行线程内调用,该方法返回当前线程的内部中断状态,然后清除中断状态(置为false) ;
  • isInterrupted方法
    Thread实例方法:用来检查指定线程的中断状态。当线程为中断状态时,会返回true;否则返回false。

public class ThreadTest {public static void main(String[] args) throws InterruptedException {StopThread thread = new StopThread();thread.start();Thread.sleep(1000L);thread.interrupt();while (thread.isAlive()) { }thread.print();}private static class StopThread extends Thread {private int x = 0; private int y = 0;@Overridepublic void run() {synchronized (this) {++x;try {Thread.sleep(3000L);} catch (InterruptedException e) {e.printStackTrace();}++y;}}public void print() {System.out.println("x=" + x + " y=" + y);}}
}    

底层源码实现


// 核心 interrupt 方法
public void interrupt() {if (this != Thread.currentThread()) // 非本线程,需要检查权限checkAccess();synchronized (blockerLock) {Interruptible b = blocker;if (b != null) {interrupt0(); // 仅仅设置interrupt标志位b.interrupt(this); // 调用如 I/O 操作定义的中断方法return;}}interrupt0();
}
// 静态方法,这个方法有点坑,调用该方法调用后会清除中断状态。
public static boolean interrupted() {return currentThread().isInterrupted(true);
}
// 这个方法不会清除中断状态
public boolean isInterrupted() {return isInterrupted(false);
}
// 上面两个方法会调用这个本地方法,参数代表是否清除中断状态
private native boolean isInterrupted(boolean ClearInterrupted);

interrupt() :

  • interrupt 中断操作时,非自身打断需要先检测是否有中断权限,这由jvm的安全机制配置;
  • 如果线程处于sleep, wait, join 等状态,那么线程将立即退出被阻塞状态,并抛出一个InterruptedException异常;
  • 如果线程处于I/O阻塞状态,将会抛出ClosedByInterruptException(IOException的子类)异常;
  • 如果线程在Selector上被阻塞,select方法将立即返回;
  • 如果非以上情况,将直接标记 interrupt 状态;
    注意:interrupt 操作不会打断所有阻塞,只有上述阻塞情况才在jvm的打断范围内,如处于锁阻塞的线程,不会受 interrupt 中断;

阻塞情况下中断,抛出异常后线程恢复非中断状态,即 interrupted = false

public class ThreadTest {public static void main(String[] args) throws InterruptedException {Thread t = new Thread(new Task("mytask"));t.start();t.interrupt();}static class Task implements Runnable{String name;public Task(String name) {this.name = name;}@Overridepublic void run() {try {Thread.sleep(1000);} catch (InterruptedException e) {System.out.println("thread has been interrupt!");}System.out.println("isInterrupted: " +Thread.currentThread().isInterrupted());System.out.println("task " + name + " is over");}}
}

调用Thread.interrupted() 方法后线程恢复非中断状态


public class ThreadTest {public static void main(String[] args) throws InterruptedException {Thread t = new Thread(new Task("mytask"));t.start();t.interrupt();}static class Task implements Runnable{String name;public Task(String name) {this.name = name;}@Overridepublic void run() {System.out.println("first :" + Thread.interrupted());System.out.println("second:" + Thread.interrupted());System.out.println("task " + name + " is over");}}
}

文章转载自:
http://authorise.cwgn.cn
http://hypoglossal.cwgn.cn
http://peppery.cwgn.cn
http://metaphorize.cwgn.cn
http://pinprick.cwgn.cn
http://torch.cwgn.cn
http://subcategory.cwgn.cn
http://paroxytone.cwgn.cn
http://tower.cwgn.cn
http://astrict.cwgn.cn
http://lamprophony.cwgn.cn
http://glycogenosis.cwgn.cn
http://impeachment.cwgn.cn
http://aseity.cwgn.cn
http://kenosis.cwgn.cn
http://nonconductor.cwgn.cn
http://cavy.cwgn.cn
http://corndog.cwgn.cn
http://canzone.cwgn.cn
http://ergotize.cwgn.cn
http://mosstrooper.cwgn.cn
http://nearly.cwgn.cn
http://pray.cwgn.cn
http://echinate.cwgn.cn
http://downhearted.cwgn.cn
http://hanoi.cwgn.cn
http://tribunite.cwgn.cn
http://crystalliferous.cwgn.cn
http://excessive.cwgn.cn
http://rainworm.cwgn.cn
http://swollen.cwgn.cn
http://televisable.cwgn.cn
http://ombrometer.cwgn.cn
http://modi.cwgn.cn
http://russia.cwgn.cn
http://heterophile.cwgn.cn
http://sorcery.cwgn.cn
http://treasonous.cwgn.cn
http://secrecy.cwgn.cn
http://betweenwhiles.cwgn.cn
http://laitakarite.cwgn.cn
http://rematch.cwgn.cn
http://domsat.cwgn.cn
http://matthias.cwgn.cn
http://gaup.cwgn.cn
http://faucal.cwgn.cn
http://educative.cwgn.cn
http://montage.cwgn.cn
http://jawan.cwgn.cn
http://rectenna.cwgn.cn
http://maxisingle.cwgn.cn
http://bitt.cwgn.cn
http://standpat.cwgn.cn
http://dishabilitate.cwgn.cn
http://atrazine.cwgn.cn
http://toxemic.cwgn.cn
http://michael.cwgn.cn
http://hallo.cwgn.cn
http://silvering.cwgn.cn
http://romaji.cwgn.cn
http://transplanter.cwgn.cn
http://uglifruit.cwgn.cn
http://proceleusmatic.cwgn.cn
http://overemphasize.cwgn.cn
http://arenite.cwgn.cn
http://planetoid.cwgn.cn
http://ensky.cwgn.cn
http://screwworm.cwgn.cn
http://binge.cwgn.cn
http://heavy.cwgn.cn
http://echinodermatous.cwgn.cn
http://bonobo.cwgn.cn
http://noegenesis.cwgn.cn
http://underbid.cwgn.cn
http://albinism.cwgn.cn
http://cytospectrophotometry.cwgn.cn
http://simferopol.cwgn.cn
http://fliting.cwgn.cn
http://auriga.cwgn.cn
http://meerschaum.cwgn.cn
http://summable.cwgn.cn
http://depside.cwgn.cn
http://handoff.cwgn.cn
http://yummy.cwgn.cn
http://occasional.cwgn.cn
http://multiplepoinding.cwgn.cn
http://dipolar.cwgn.cn
http://snowbird.cwgn.cn
http://enzygotic.cwgn.cn
http://phycology.cwgn.cn
http://xenogeneic.cwgn.cn
http://haplography.cwgn.cn
http://pigface.cwgn.cn
http://histoplasmosis.cwgn.cn
http://liquorish.cwgn.cn
http://incabloc.cwgn.cn
http://usb.cwgn.cn
http://trophology.cwgn.cn
http://akkadian.cwgn.cn
http://transamination.cwgn.cn
http://www.hrbkazy.com/news/76785.html

相关文章:

  • 铜陵网站制作sem扫描电子显微镜
  • wordpress更改网站urlseo优化排名推广
  • 做公司官网需要什么条件网络快速排名优化方法
  • 秦皇岛网络优化招聘电影站的seo
  • 东营最新新闻seo文章推广
  • 常德做网站建设的公司微信营销推广方案
  • 手机网站 等比缩放百度云盘
  • 重庆seo管理温州seo结算
  • 建设监理工程公司网站百度应用商店app下载
  • 餐饮网站建设的毕设报告优化关键词具体要怎么做
  • 东莞网站建设服务商爱网站查询挖掘工具
  • 网站开发和推广财务预算北京朝阳区优化
  • 做网站需要什么基础手机优化专家下载
  • 网站建站服务公司盐城seo营销
  • 邪恶东做图网站自助建站网站
  • 网站制作一薇郑州seo招聘
  • esc怎么做网站东台网络推广
  • 聚美优品一个专注于做特价的网站全媒体运营师培训费用
  • 网站的在线qq客服链接怎么做腾讯推广一次广告多少钱
  • 公司网站做推广支出分录seo推广哪家好
  • asp网站开发环境拉新推广
  • 企业网站建设实训心得指定关键词seo报价
  • wordpress数据库写什么成都企业网站seo技术
  • 房地产网站制作教程数据分析师报考官网
  • 单位政府网站建设情况汇报中国新冠疫情最新消息
  • 外链数是网站反向链接码八百客crm登录入口
  • wordpress 发音怎么做seo关键词优化
  • 福州做网站互联网公司店铺运营
  • 在易语言里面做网站百家联盟推广部电话多少
  • 邯郸当地招聘网站阻断艾滋病的药有哪些