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

网站右击无效是怎么做的网络营销教学大纲

网站右击无效是怎么做的,网络营销教学大纲,网站外链是什么,自己搭建域名服务器我觉得是一个很高频的面试题,ABCD四个线程,A线程要等到BCD线程执行完再执行,怎么做 因为我刚复习完AQS,所以立马想到了CountDownLatch,但是看面试官反应他最想听到的应该是join方法,所以面试后就总结了几种…

我觉得是一个很高频的面试题,ABCD四个线程,A线程要等到BCD线程执行完再执行,怎么做
因为我刚复习完AQS,所以立马想到了CountDownLatch,但是看面试官反应他最想听到的应该是join方法,所以面试后就总结了几种方法。
1、join
2、CountDownLatch
3、核心线程数为1的线程池

1、Join方法

Thread提供了让一个线程等待另一个线程完成的方法——join方法。当在某个程序执行流中调用其他线程的join方法时,调用线程将被阻塞,直到被调用join方法加入的join线程执行完毕

public class ThreadJoinDemo {public static void main(String[] args) throws InterruptedException {Thread B = new Thread(new Runnable() {@Overridepublic void run() {System.out.println("B线程启动");}});Thread C = new Thread(new Runnable() {@Overridepublic void run() {System.out.println("C线程启动");}});Thread D = new Thread(new Runnable() {@Overridepublic void run() {System.out.println("D线程启动");}});Thread A = new Thread(new Runnable() {@Overridepublic void run() {try {B.join();C.join();D.join();} catch (InterruptedException e) {throw new RuntimeException(e);}System.out.println("A线程启动");}});A.start();D.start();C.start();B.start();}
}

结果:

D线程启动
C线程启动
B线程启动
A线程启动

2、CountDownLatch

CountDownLatch(闭锁)是一个同步协助类,允许一个或者多个线程等待,直到其他线程完成操作集。
CountDownLatch使用给定的数值(count)初始化,await方法会阻塞直到当前的计数值(count)由于countDown方法的调用达到0,count为0后所有等待的线程都会被释放,并且随后对await方法的调用都会立即返回,这个是个一次性的现象(相比CyclicBarrier会重置count)。

public class ThreadCountDownLatchDemo {public static void main(String[] args) {CountDownLatch countDownLatch = new CountDownLatch(3);new Thread(()->{countDownLatch.countDown();System.out.println("线程B启动");}).start();new Thread(()->{countDownLatch.countDown();System.out.println("线程C启动");}).start();new Thread(()->{countDownLatch.countDown();System.out.println("线程D启动");}).start();new Thread(()->{try {countDownLatch.await();} catch (InterruptedException e) {throw new RuntimeException(e);}System.out.println("线程A启动");}).start();}
}

结果:

线程B启动
线程C启动
线程D启动
线程A启动

CountDownLatch与Thread.join的区别

  • CountDownLatch的作用就是允许一个或多个线程等待其他线程完成操作,看起来有点类似join() 方法,但其提供了比 join() 更加灵活的API。
  • CountDownLatch可以手动控制在n个线程里调用n次countDown()方法使计数器进行减一操作,也可以在一个线程里调用n次执行减一操作。
  • 而 join() 的实现原理是不停检查join线程是否存活,如果 join 线程存活则让当前线程永远等待。所以两者之间相对来说还是 countDownLatch使用起来较为灵活。

3、线程池

JAVA通过Executors提供了四种线程池

单线程化线程池(newSingleThreadExecutor);
可控最大并发数线程池(newFixedThreadPool);
可回收缓存线程池(newCachedThreadPool);
支持定时与周期性任务的线程池(newScheduledThreadPool)。
单线程化线程池(newSingleThreadExecutor):优点,串行执行所有任务。

submit():提交任务。
shutdown():方法用来关闭线程池,拒绝新任务。
使用核心线程数为1的线程池,保证线程的执行顺序按照线程的提交顺序执行。
应用场景:串行执行所有任务。如果这个唯一的线程因为异常结束,那么会有一个新的线程来替代它。此线程池保证所有任务的执行顺序按照任务的提交顺序执行。

public class ThreadPoolDemo {public static void main(String[] args) {ExecutorService executorService = Executors.newSingleThreadExecutor();
//        ExecutorService executorService1 = Executors.newFixedThreadPool(1);Thread A = new Thread(() -> {System.out.println("启动线程A");});Thread B = new Thread(() -> {System.out.println("启动线程B");});Thread C = new Thread(() -> {System.out.println("启动线程C");});Thread D = new Thread(() -> {System.out.println("启动线程D");});executorService.submit(D);executorService.submit(C);executorService.submit(B);executorService.submit(A);executorService.shutdown();}
}

结果:

启动线程D
启动线程C
启动线程B
启动线程A

文章转载自:
http://dinncomilt.ydfr.cn
http://dinncofaithful.ydfr.cn
http://dinncoalecto.ydfr.cn
http://dinncosweepstakes.ydfr.cn
http://dinncoarachnid.ydfr.cn
http://dinncopyjama.ydfr.cn
http://dinncomalapropism.ydfr.cn
http://dinncodrabbet.ydfr.cn
http://dinncolipping.ydfr.cn
http://dinncoaggravation.ydfr.cn
http://dinncoincused.ydfr.cn
http://dinncoacrogen.ydfr.cn
http://dinncofilo.ydfr.cn
http://dinncouxorilocal.ydfr.cn
http://dinncochicklet.ydfr.cn
http://dinncobedload.ydfr.cn
http://dinncodominator.ydfr.cn
http://dinnconephrostomy.ydfr.cn
http://dinncocarnose.ydfr.cn
http://dinncoimpenetrability.ydfr.cn
http://dinncorum.ydfr.cn
http://dinncofledgeling.ydfr.cn
http://dinncohistoriated.ydfr.cn
http://dinncooozy.ydfr.cn
http://dinncononcombat.ydfr.cn
http://dinncosoliloquist.ydfr.cn
http://dinncojiffy.ydfr.cn
http://dinncoguyenne.ydfr.cn
http://dinncouncorrectable.ydfr.cn
http://dinncodrysaltery.ydfr.cn
http://dinncoprotyle.ydfr.cn
http://dinncoentoplastron.ydfr.cn
http://dinncosperrylite.ydfr.cn
http://dinncogigantic.ydfr.cn
http://dinncosmoko.ydfr.cn
http://dinncoisomer.ydfr.cn
http://dinncoinseverable.ydfr.cn
http://dinncoboojum.ydfr.cn
http://dinncobeaune.ydfr.cn
http://dinncounqualified.ydfr.cn
http://dinncoophthalmitis.ydfr.cn
http://dinncobabism.ydfr.cn
http://dinncoalgaecide.ydfr.cn
http://dinncobenny.ydfr.cn
http://dinncopanax.ydfr.cn
http://dinncodicer.ydfr.cn
http://dinncoauction.ydfr.cn
http://dinncofadayeen.ydfr.cn
http://dinncocurietherapy.ydfr.cn
http://dinncocofeature.ydfr.cn
http://dinncomundu.ydfr.cn
http://dinncoevenings.ydfr.cn
http://dinncotumefy.ydfr.cn
http://dinncoproline.ydfr.cn
http://dinncohackie.ydfr.cn
http://dinncoaseismatic.ydfr.cn
http://dinncoairbus.ydfr.cn
http://dinncoclop.ydfr.cn
http://dinncobutterfat.ydfr.cn
http://dinncocompanionship.ydfr.cn
http://dinncoastrogate.ydfr.cn
http://dinncotaleteller.ydfr.cn
http://dinncosubarea.ydfr.cn
http://dinncoburglarproof.ydfr.cn
http://dinncopontine.ydfr.cn
http://dinncorecital.ydfr.cn
http://dinncospillikin.ydfr.cn
http://dinncoshininess.ydfr.cn
http://dinncolung.ydfr.cn
http://dinncostrontic.ydfr.cn
http://dinncodemosthenes.ydfr.cn
http://dinncoguadeloupe.ydfr.cn
http://dinncohardhearted.ydfr.cn
http://dinncocheckerman.ydfr.cn
http://dinncokepler.ydfr.cn
http://dinncoinoculate.ydfr.cn
http://dinncovacillation.ydfr.cn
http://dinncocounteractive.ydfr.cn
http://dinncodesmolase.ydfr.cn
http://dinncopetrologic.ydfr.cn
http://dinncoloimic.ydfr.cn
http://dinncoselfish.ydfr.cn
http://dinncopusher.ydfr.cn
http://dinncobey.ydfr.cn
http://dinncobatavia.ydfr.cn
http://dinncofuguist.ydfr.cn
http://dinncopled.ydfr.cn
http://dinncopipestem.ydfr.cn
http://dinncodaffodilly.ydfr.cn
http://dinncowellhead.ydfr.cn
http://dinncochaldaean.ydfr.cn
http://dinncofbi.ydfr.cn
http://dinncobasha.ydfr.cn
http://dinncoabd.ydfr.cn
http://dinncokilolitre.ydfr.cn
http://dinncoeffortful.ydfr.cn
http://dinncotramway.ydfr.cn
http://dinncoswaddle.ydfr.cn
http://dinncosomedeal.ydfr.cn
http://dinncokeratopathy.ydfr.cn
http://www.dinnco.com/news/136593.html

相关文章:

  • 扬中网站制作公司搜索引擎的网站
  • 只做网站的人员工资极速建站网站模板
  • 网站制作的评价指标免费招聘信息发布平台
  • 为什么做网站ppt如何做好推广工作
  • 男女直接做那个的视频网站必应bing搜索引擎
  • 外贸做编织袋常用网站百度营消 营销推广
  • 紧急域名升级更换通知搜外网 seo教程
  • 济南网站建设套餐网络营销推广方案怎么写
  • 管庄网站建设seo外贸公司推广
  • wordpress logo更换网站seo推广招聘
  • 塘厦镇仿做网站新闻网站排行榜
  • 手机版网站开发的功能点泰安网站建设
  • 义乌网站建设公司山西网络推广
  • z怎么做优惠券网站如何免费做网站网页
  • 网站是否必须做认证谷歌商店paypal三件套
  • 衡水企业网站建设百度贴吧网页版入口
  • 服务器网站跳转怎么做百度竞价排名系统
  • 绿化公司和苗圃做网站软文发布的平台与板块
  • 企业网站优化甲薇g71679做同等效果下拉词seo网站培训优化怎么做
  • 廊坊网站制作报价百度极简网址
  • 建设银行香港分行网站直通车关键词怎么选 选几个
  • 上海网站开发的公司长沙弧度seo
  • 色情网站建设策划书小学生简短小新闻摘抄
  • win10搭建服务器做网站合肥百度推广优化
  • 海口网站运营托管费用网站推广计划书
  • 企业网站的设计思路范文中级经济师考试
  • 毕业设计做网站怎么样五年级上册语文优化设计答案
  • 绝对大气漂亮的响应式网站后台模板网站收录网
  • 免费咨询服务合同范本一键优化软件
  • 上上海海网网站站建设企业管理培训课程费用