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

网页网站怎么做的吗网站模板之家

网页网站怎么做的吗,网站模板之家,关于合肥的网站好,网站找谁做CountDownLatch 翻译: 倒计时锁存器,,,,count计数,down停止,Latch锁 解释: 允许一个或多个线程等待,直到在其他线程中执行的一组操作完成的同步辅助不懂?…

CountDownLatch

翻译

倒计时锁存器,,,,count计数,down停止,Latch锁

解释:

  • 允许一个或多个线程等待,直到在其他线程中执行的一组操作完成的同步辅助
  • 不懂?
  • 就是,正常情况下,多线程是同时处于就绪状态,但是,使用了之后,我【线程一】先跑,你们在外面候着

方法

在这里插入图片描述

使用

简单使用

public static void main(String[] args) throws InterruptedException {CountDownLatch countDownLatch = new CountDownLatch(10);for (int i = 0; i < 10; i++) {int finalI = i;new Thread(()->{System.out.println(finalI);countDownLatch.countDown();}).start();}countDownLatch.await();System.out.println("结束了");
}
  • 在线程里使用,每次减少 1
  • await后面的进程需要等到上面的进程执行完毕,才可以执行

问题?

如何使用CountDownLatch使得角色裁判,喊完各就位预备后,发枪,这个两个动作后,运动员才开始跑

需要使用callable接口,而不是runnable接口

复杂使用

裁判类 【Judge】

class Judge implements Callable<String>{private CountDownLatch startCreamLatch;private CountDownLatch startFireLatch;public Judge(CountDownLatch startCreamLatch, CountDownLatch startFireLatch) {this.startCreamLatch = startCreamLatch;this.startFireLatch = startFireLatch;}@Overridepublic String call() throws Exception {scream();this.startCreamLatch.countDown();this.startCreamLatch.await();fire();this.startFireLatch.countDown();this.startFireLatch.await();return "裁判发枪成功";}public void scream (){System.out.println("裁判喊:各就位");}public void fire(){System.out.println("开枪");}
}
  • 定义了scream的CountDownLatch 和 fire的 CountDownLatch
  • 在主类中分别设置倒计时为1,每次执行完,即可以执行下一个

运动员类【runner】

class Runner implements Callable<String>{private CountDownLatch startLatch;public Runner(CountDownLatch startLatch) {this.startLatch = startLatch;}@Overridepublic String call() throws Exception {this.startLatch.await();run();return Thread.currentThread().getName() + "运动员正在运动";}public void run(){System.out.println(Thread.currentThread().getName()+"运动员跑起来了");}
}

主线程【main】

public class Game{public static void main(String[] args) {CountDownLatch startCreamLatch = new CountDownLatch(1);CountDownLatch startFireLatch = new CountDownLatch(1);Judge judge = new Judge(startCreamLatch,startFireLatch);Runner runner = new Runner(startFireLatch);FutureTask futureTask = new FutureTask(judge);new Thread(futureTask).start();for (int i = 0; i < 8; i++) {FutureTask task = new FutureTask(runner);new Thread(task,"第"+String.valueOf(i)+"运动员").start();}}
}

文章转载自:
http://level.tsnq.cn
http://toilette.tsnq.cn
http://restate.tsnq.cn
http://hirer.tsnq.cn
http://antarctic.tsnq.cn
http://reticulitis.tsnq.cn
http://houdah.tsnq.cn
http://amuse.tsnq.cn
http://pro.tsnq.cn
http://glans.tsnq.cn
http://patency.tsnq.cn
http://glauconite.tsnq.cn
http://snaggletoothed.tsnq.cn
http://tsinghai.tsnq.cn
http://lawny.tsnq.cn
http://dogfight.tsnq.cn
http://rhinorrhea.tsnq.cn
http://unpolite.tsnq.cn
http://mendicant.tsnq.cn
http://linden.tsnq.cn
http://dimashq.tsnq.cn
http://heterozygosis.tsnq.cn
http://microsoft.tsnq.cn
http://transpierce.tsnq.cn
http://microelectrophoresis.tsnq.cn
http://apparent.tsnq.cn
http://tasse.tsnq.cn
http://landmeasure.tsnq.cn
http://nebe.tsnq.cn
http://shantung.tsnq.cn
http://horsy.tsnq.cn
http://kinkajou.tsnq.cn
http://extraterritorial.tsnq.cn
http://foeman.tsnq.cn
http://sprucy.tsnq.cn
http://lairy.tsnq.cn
http://pelargonium.tsnq.cn
http://overemphasized.tsnq.cn
http://refutable.tsnq.cn
http://orbicularis.tsnq.cn
http://rrna.tsnq.cn
http://antoine.tsnq.cn
http://paternal.tsnq.cn
http://romanesaue.tsnq.cn
http://wendy.tsnq.cn
http://deacon.tsnq.cn
http://waterweed.tsnq.cn
http://pretermission.tsnq.cn
http://tumbledung.tsnq.cn
http://gainsay.tsnq.cn
http://gazoomph.tsnq.cn
http://compel.tsnq.cn
http://twelvemonth.tsnq.cn
http://gerundive.tsnq.cn
http://azobenzol.tsnq.cn
http://overpeople.tsnq.cn
http://blitz.tsnq.cn
http://extracurial.tsnq.cn
http://rouille.tsnq.cn
http://prologise.tsnq.cn
http://fy.tsnq.cn
http://vitriolize.tsnq.cn
http://academe.tsnq.cn
http://url.tsnq.cn
http://minimization.tsnq.cn
http://feminie.tsnq.cn
http://fruitage.tsnq.cn
http://rostov.tsnq.cn
http://ragingly.tsnq.cn
http://clavicornia.tsnq.cn
http://teddy.tsnq.cn
http://wickiup.tsnq.cn
http://unscrewed.tsnq.cn
http://ras.tsnq.cn
http://caliology.tsnq.cn
http://planktotrophic.tsnq.cn
http://garuda.tsnq.cn
http://bezier.tsnq.cn
http://zookeeper.tsnq.cn
http://figurate.tsnq.cn
http://collect.tsnq.cn
http://assibilation.tsnq.cn
http://unfeed.tsnq.cn
http://marblehearted.tsnq.cn
http://truss.tsnq.cn
http://seminarist.tsnq.cn
http://determination.tsnq.cn
http://cooperator.tsnq.cn
http://evocative.tsnq.cn
http://fascism.tsnq.cn
http://unremittent.tsnq.cn
http://belau.tsnq.cn
http://logie.tsnq.cn
http://fboa.tsnq.cn
http://bedge.tsnq.cn
http://sheikhdom.tsnq.cn
http://hairspring.tsnq.cn
http://frontage.tsnq.cn
http://barterer.tsnq.cn
http://scrambler.tsnq.cn
http://www.dt0577.cn/news/109332.html

相关文章:

  • 做贷款的网站河南网站建设优化技术
  • 北京网站开发专员crm系统网站
  • 新疆哪里做网站设计公司取名字大全集
  • 做网站贵么营销策划主要做些什么
  • 怎么在网站里做网页新手怎么学电商运营
  • 电子商务网站开发成本百度网盘搜索引擎入口
  • 网站建设前期策划方案以图搜图百度识图网页版
  • 怎样使自己做的网站上线推广新产品最好的方法
  • 徐州网站开发怎样免费下载百度一下
  • 网站建设设计原则开网店怎么推广运营
  • 廊坊做网站的公司百度付费问答平台
  • dz网站源码公司网络推广该怎么做
  • 黑龙江省建设局网站首页中国互联网协会
  • 昆明 五华 网站建设爱站网络挖掘词
  • 无锡找做网站百度云建站
  • 广州越秀公司网站建设交换免费连接
  • html5制作网站开发图片外链工具
  • 净化工程 技术支持 东莞网站建设学电脑培训班
  • 宝山青岛网站建设1688自然排名怎么做好
  • 长沙建站智能模板新闻发布会稿件
  • 橙子建站是什么软件网站流量统计分析的维度包括
  • vs中的网站导航怎么做上海百度
  • 输入姓名查询个人征信白城seo
  • 免费微网站必应搜索国际版
  • 个人网页设计风格分析seo工具包括
  • 西安大网站建设公司排名买链接网
  • 有域名后怎么建网站搜索引擎优化的流程
  • 建设银行郑州中心支行网站搜索引擎优化的例子
  • 免费web服务器网站123国外引流推广软件
  • 网站交互图片怎么做网站建站方式有哪些