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

诸城网站做的好的附近装修设计公司

诸城网站做的好的,附近装修设计公司,苏州网站开发建设,视频分享网站怎么做的一个线程如何知道另一线程已经结束#xff1f;Thread类提供了回答此问题的方法。有两种方法可以判定一个线程是否结束。第一#xff0c;可以在线程中调用isAlive()。这种方法由Thread定义#xff0c;它的通常形式如下#xff1a;final boolean isAlive( )如果所调用线程仍在…一个线程如何知道另一线程已经结束Thread类提供了回答此问题的方法。有两种方法可以判定一个线程是否结束。第一可以在线程中调用isAlive()。这种方法由Thread定义它的通常形式如下final boolean isAlive( )如果所调用线程仍在运行isAlive()方法返回true如果不是则返回false。但isAlive()很少用到等待线程结束的更常用的方法是调用join()描述如下final void join( ) throws InterruptedException该方法等待所调用线程结束。该名字来自于要求线程等待直到指定线程参与的概念。join()的附加形式允许给等待指定线程结束定义一个最大时间。下面是前面例子的改进版本。运用join()以确保主线程最后结束。同样它也演示了isAlive()方法。// Using join() to wait for threads to finish.class NewThread implements Runnable {String name; // name of threadThread t;NewThread(String threadname) {name threadname;t new Thread(this, name);System.out.println(New thread: t);t.start(); // Start the thread}// This is the entry point for thread.public void run() {try {for(int i 5; i 0; i--) {System.out.println(name : i);Thread.sleep(1000);}} catch (InterruptedException e) {System.out.println(name interrupted.);}System.out.println(name exiting.);}}class DemoJoin {public static void main(String args[]) {NewThread ob1 new NewThread(One);NewThread ob2 new NewThread(Two);NewThread ob3 new NewThread(Three);System.out.println(Thread One is alive: ob1.t.isAlive());System.out.println(Thread Two is alive: ob2.t.isAlive());System.out.println(Thread Three is alive: ob3.t.isAlive());// wait for threads to finishtry {System.out.println(Waiting for threads to finish.);ob1.t.join();ob2.t.join();ob3.t.join();} catch (InterruptedException e) {System.out.println(Main thread Interrupted);}System.out.println(Thread One is alive: ob1.t.isAlive());System.out.println(Thread Two is alive: ob2.t.isAlive());System.out.println(Thread Three is alive: ob3.t.isAlive());System.out.println(Main thread exiting.);}}程序输出如下所示New thread: Thread[One,5,main]New thread: Thread[Two,5,main]New thread: Thread[Three,5,main]Thread One is alive: trueThread Two is alive: trueThread Three is alive: trueWaiting for threads to finish.One: 5Two: 5Three: 5One: 4Two: 4Three: 4One: 3Two: 3Three: 3One: 2Two: 2Three: 2One: 1Two: 1Three: 1Two exiting.Three exiting.One exiting.Thread One is alive: falseThread Two is alive: falseThread Three is alive: falseMain thread exiting.如你所见调用join()后返回线程终止执行。
http://www.huolong8.cn/news/95779/

相关文章:

  • 宁波北仑网站网页建设网站的投票 计数模块怎么做
  • 网站建设需要那些人才网站没有问题但是一直做不上首页
  • wordpress 错误上海外贸seo
  • 纯代码添加wordpress网站底部导航郑州网络科技公司有哪些
  • 亚马逊欧洲站wordpress 下载附件
  • 深圳网站建设培训机构网站建设期末作业要求
  • 大连哪家公司做网站好北京高端定制网站建设
  • 利津网站建设哪家好软件开发软件定制
  • 阳江市网站建设网络设计师干什么的
  • 医联媒体网站建设南昌 网站 公司
  • 重庆建网站方法ai网站
  • 网络推广商城网站小公司网站建设需要多少钱
  • 福安做网站最好网站做301根目录在哪里
  • 德州市网站建设合肥网站建设ahyeda
  • 上海方正大厦网站建设大连seo排名外包
  • 网站建设开发报告论文北京网站建设与维护
  • 定制型网站开发哪家公司做网站建设比较好
  • 简单风景网站模版网站想换一个空间怎么办
  • 料神wordpress建站教程网站建站价格
  • 网站建设地址北京昌平重庆推广一个网站
  • 烟台学校网站建设长宁广州网站建设
  • 扬州建设银行网站企业营销型网站规划
  • 弹幕网站开发律师做网络推广最好的网站有哪些
  • 有哪些做网站好的公司wordpress dcloud
  • 做电影网站犯罪吗企业网站建设原则
  • 网站建设合作协议模板wordpress搭建小程序
  • 青岛市黄岛区城市建设局网站太原专业制作网站
  • 象刀设计网站计算机专业培训机构排名
  • 深圳高端网站定制烟台企业网站建设公司
  • 个人网站 后台管理seowhy官网