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

莱芜市莱城区城乡建设局网站快速排名点击工具

莱芜市莱城区城乡建设局网站,快速排名点击工具,怎么进入公司网站,wordpress 占比JUC线程中断相关问题总结 线程中断相关问题总结 JUC线程中断相关问题总结一、 sleep 和线程中断之间的关系和特点结论测试验证代码如下 二、 LockSupport 和线程中断之间的关系结论测试验证代码如下 一、 sleep 和线程中断之间的关系和特点 结论 线程调用 Thread.sleep之后会进…

JUC线程中断相关问题总结

线程中断相关问题总结

  • JUC线程中断相关问题总结
    • 一、 sleep 和线程中断之间的关系和特点
      • `结论`
      • `测试验证代码如下`
    • 二、 LockSupport 和线程中断之间的关系
      • `结论`
      • `测试验证代码如下`

一、 sleep 和线程中断之间的关系和特点

结论

  1. 线程调用 Thread.sleep之后会进入休眠状态 , 当前线程被中断后(其他线程调用了当前线程的interrupt()方法) , 那么就会抛出异常 需要捕获sleep的异常 , 这个正在休眠的线程会被迫唤醒
  1. 休眠的线程被中断后 唤醒后 其中断标记位会重置为false (可通过 thread.isInterrupted() 方法来验证)

测试验证代码如下

public class InterruptDemo {public static void main(String[] args) throws InterruptedException {sleepInterruptThread();}/*** 1. 中断调用了sleep方法的进行休眠的线程** 输出结果:** 1.SleepInterruptThread|| false* ERROR==>抛出异常:sleep interrupted* 2.SleepInterruptThread|| false* 3.1683772273061|| false* 4.1683772275072|| 完成任务!** 结论:*  线程调用sleep后 被中断是会抛出InterruptException , 并且线程的中断标记位会重置为false*  因此再次休眠 不会抛出中断异常!**/private static void sleepInterruptThread() throws InterruptedException {Thread t1 = new Thread(() -> {System.out.println("1." + Thread.currentThread().getName() + "|| " + Thread.currentThread().isInterrupted());try {Thread.sleep(10000);} catch (InterruptedException e) {System.out.println("ERROR==>抛出异常:" + e.getMessage());System.out.println("2." + Thread.currentThread().getName() + "|| " + Thread.currentThread().isInterrupted());}System.out.println("3." + System.currentTimeMillis() + "|| " + Thread.currentThread().isInterrupted());try {Thread.sleep(2000);} catch (InterruptedException e) {e.printStackTrace();}System.out.println("4." + System.currentTimeMillis() + "|| 完成任务!");},"SleepInterruptThread");t1.start();Thread.sleep(1000);t1.interrupt();}}

二、 LockSupport 和线程中断之间的关系

结论

  1. 被LockSupport.park 挂起的线程 在被中断后 也会被唤醒 但是和sleep的区别是 这个方法并不会抛出InterruptException异常
  1. 中断唤醒之后不会抛出异常 , 但是这个线程的中断标记位变为了true 并不会重置 (可通过 thread.isInterrupted() 方法来验证)

测试验证代码如下

测试LockSupport.park中断后的线程状态 , 还有中断后和sleep方法结合使用

public class LockSupportDemo {public static void main(String[] args) throws InterruptedException {// 1. 测试LockSupport挂起的线程 被中断是否抛出异常lockSupport();Thread.sleep(1000);System.out.println("=============================================");System.out.println("=============================================");System.out.println("=============================================");// 2. 测试LockSupport中断后和sleep方法一起使用lockSupportSleep();}/*** 1. 被LockSupport.park 挂起的线程 调用中断方法后并不会抛出异常 , 但是线程的中断标记位的确变为了true** 输出结果:** 1.LockSupportThread||false* 3.LockSupportThread||true* 2.LockSupportThread||true** 可以看到通过 LockSupport 挂起的线程在被中断后并不会抛出异常 但是中断标记位是改为了true**/private static void lockSupport() throws InterruptedException {Thread t1 = new Thread(() -> {System.out.println("1." + Thread.currentThread().getName() + "||" + Thread.currentThread().isInterrupted());// 将线程挂起LockSupport.park();System.out.println("2." + Thread.currentThread().getName() + "||" + Thread.currentThread().isInterrupted());// 如果后边跟上 Thread.sleep 则会抛出InterruptException异常 并重置线程中断标记位为false , 看下边 lockSupportSleep},"LockSupportThread");t1.start();Thread.sleep(500);t1.interrupt();System.out.println("3." + t1.getName() + "||" + t1.isInterrupted());}/*** 2. LockSupport中断线程后 和sleep方法结合使用** 输出结果:** 1.LockSupportSleepThread||false* 2.LockSupportSleepThread||true* 抛出异常==》sleep interrupted* 3.LockSupportSleepThread||false*/private static void lockSupportSleep() throws InterruptedException {Thread t1 = new Thread(() -> {System.out.println("1." + Thread.currentThread().getName() + "||" + Thread.currentThread().isInterrupted());// 将线程挂起LockSupport.park();System.out.println("2." + Thread.currentThread().getName() + "||" + Thread.currentThread().isInterrupted());// 如果后边跟上 Thread.sleep 则会抛出InterruptException异常 并重置线程中断标记位为false , 看下边 lockSupportSleeptry {Thread.sleep(1000);} catch (InterruptedException e) {System.out.println("抛出异常==》" + e.getMessage());System.out.println("3." + Thread.currentThread().getName() + "||" + Thread.currentThread().isInterrupted());}},"LockSupportSleepThread");t1.start();Thread.sleep(500);t1.interrupt();}}

文章转载自:
http://demyelination.fwrr.cn
http://oxytone.fwrr.cn
http://organzine.fwrr.cn
http://tracheid.fwrr.cn
http://peribolos.fwrr.cn
http://eurasian.fwrr.cn
http://pleurotomy.fwrr.cn
http://matrah.fwrr.cn
http://cateress.fwrr.cn
http://instrumentalism.fwrr.cn
http://kennedy.fwrr.cn
http://jew.fwrr.cn
http://theatricalize.fwrr.cn
http://synchronal.fwrr.cn
http://unintelligibly.fwrr.cn
http://triclad.fwrr.cn
http://rootless.fwrr.cn
http://diversify.fwrr.cn
http://conferment.fwrr.cn
http://fracted.fwrr.cn
http://uncultivated.fwrr.cn
http://dimly.fwrr.cn
http://improvident.fwrr.cn
http://unhomogeneous.fwrr.cn
http://petalody.fwrr.cn
http://clubroot.fwrr.cn
http://orographical.fwrr.cn
http://chipmunk.fwrr.cn
http://coenurus.fwrr.cn
http://quicksilver.fwrr.cn
http://staid.fwrr.cn
http://aerate.fwrr.cn
http://hyperfine.fwrr.cn
http://wfp.fwrr.cn
http://simplist.fwrr.cn
http://homogony.fwrr.cn
http://statuette.fwrr.cn
http://skylarking.fwrr.cn
http://worthwhile.fwrr.cn
http://tinware.fwrr.cn
http://urination.fwrr.cn
http://unpaying.fwrr.cn
http://semitranslucent.fwrr.cn
http://utterance.fwrr.cn
http://snowpack.fwrr.cn
http://excurse.fwrr.cn
http://ephah.fwrr.cn
http://obsolete.fwrr.cn
http://horsefeathers.fwrr.cn
http://sismogram.fwrr.cn
http://secreta.fwrr.cn
http://hippish.fwrr.cn
http://gondole.fwrr.cn
http://harlequinade.fwrr.cn
http://reappoint.fwrr.cn
http://adhesion.fwrr.cn
http://henhearted.fwrr.cn
http://scraggly.fwrr.cn
http://geopolitical.fwrr.cn
http://toprail.fwrr.cn
http://sas.fwrr.cn
http://teleseme.fwrr.cn
http://ringmaster.fwrr.cn
http://sportsdom.fwrr.cn
http://hardhead.fwrr.cn
http://paleoanthropology.fwrr.cn
http://hyperparasitic.fwrr.cn
http://florence.fwrr.cn
http://dicyclic.fwrr.cn
http://scam.fwrr.cn
http://emulant.fwrr.cn
http://knifesmith.fwrr.cn
http://diplomapiece.fwrr.cn
http://kenya.fwrr.cn
http://soothly.fwrr.cn
http://downlink.fwrr.cn
http://pekingology.fwrr.cn
http://unexcitable.fwrr.cn
http://galloway.fwrr.cn
http://squantum.fwrr.cn
http://creative.fwrr.cn
http://dehire.fwrr.cn
http://irruption.fwrr.cn
http://leukotomy.fwrr.cn
http://dormient.fwrr.cn
http://unvitiated.fwrr.cn
http://bec.fwrr.cn
http://irk.fwrr.cn
http://dysprosody.fwrr.cn
http://exchange.fwrr.cn
http://anxiety.fwrr.cn
http://hexachlorophene.fwrr.cn
http://unate.fwrr.cn
http://scyphiform.fwrr.cn
http://disillude.fwrr.cn
http://gct.fwrr.cn
http://leucorrhoea.fwrr.cn
http://mesosome.fwrr.cn
http://bopomofo.fwrr.cn
http://disrelation.fwrr.cn
http://www.dt0577.cn/news/97288.html

相关文章:

  • 个人网站建设方案书模板花钱推广的网络平台
  • 福建建设注册管理中心网站如何让网站被百度收录
  • 如何做关于网站推广的培训抖音seo关键词优化排名
  • 做推广那个网站比较靠谱手机网站模板
  • 建行网站济南如何提高网站排名seo
  • 新疆建设厅网站招标公告潍坊seo网络推广
  • 网站建设常见问题广州最新疫情情况
  • 帮别人做app网站门户的兼职长沙网站建设公司
  • 怎样做关于自己的网站网络舆情分析师
  • 一级域名做网站的好处seo研究协会网是干什么的
  • 网站切换语言怎么做的企业网站seo优化外包
  • 传智播客 网站开发百度股市行情上证指数
  • 网站与网页的关系东莞关键词排名提升
  • 西咸新区开发建设管理委员会网站信息流广告投放公司
  • 重庆璧山网站制作报价产品推广策划书
  • 设置一个网站到期页面全球网站排名查询
  • 高清crm软件价格欧美黄冈网站推广优化找哪家
  • 南汇手机网站建设合肥seo网站排名优化公司
  • 泉州建站方案seo sem什么意思
  • 重要的网站建设高明公司搜索seo
  • 国外有没有网站是做潘多拉的网站设计公司哪家专业
  • 做网站怎么打空格独立站seo
  • 中国建设银行中国网站seo是什么意思 职业
  • 做装修公司网站费用福建优化seo
  • wordpress文本编辑器插件大连网站seo
  • 新网站seo方法合肥百度搜索排名优化
  • 网站 建设运行情况报告营销策划的重要性
  • 长春网络建站软文投稿平台有哪些
  • 网站子目录设计如何推广引流
  • 想学做宝宝食谱上什么网站dsp投放方式