例的结果,下面的:

  main thread starting…

  Thrad 2 staring…

  Thrad 2 end…

  Thrad 4 staring…

  Thrad 4 end…

  Thrad 1 staring…

  Thrad 1 end…

  Thrad 3 staring…

  Thrad 3 end…

  Thrad 5 staring…

  Thrad 5 end…

  main thread end…

  CountDownLatch方式代码例如以下:

  package com.test.thread;

  import java.util.concurrent.CountDownLatch;

  public class MyThread2 extends Thread

  {

  private CountDownLatch count;

  public MyThread2(CountDownLatch count, String name)

  {

  this.count = count;

  this.setName(name)。

  }

  @Override

  public void run()

  {

  System.out.println(this.getName() + " staring…");

  System.out.println(this.getName() + " end…")。

  this.count.countDown();

  }

  /**

  * @param args

  */

  public static void main(String[] args)

  {

  System.out.println("main thread starting…");

  CountDownLatch count = new CountDownLatch(5);

  for (int i = 1; i <= 5; i++)

  {

  MyThread2 my = new MyThread2(count, "Thread " + i);

  my.start()。

  }

  try

  {

  count.await()。

  }

  catch (InterruptedException e)

  {

  e.printStackTrace();

  }

  System.out.println("main thread end…")。

  }

  }

  执行结果例如以下:

  main thread starting…

  Thread 2 staring…

  Thread 2 end…

  Thread 4 staring…

  Thread 4 end…

  Thread 1 staring…

  Thread 1 end…

  Thread 3 staring…

  Thread 3 end…

  Thread 5 staring…

  Thread 5 end…

  main thread end…

main thread starting…的更多相关文章

  1. jupyter notebook中出现ValueError: signal only works in main thread 报错 即 长时间in[*] 解决办法

    我在jupyter notebook中新建了一个基于py3.6的kernel用来进行tensorflow学习 但是在jupyter notebook中建立该kernel时,右上角总是显示 服务正在启动 ...

  2. Why NSAttributedString import html must be on main thread?

    The HTML importer should not be called from a background thread (that is, the options dictionary inc ...

  3. 13、主线程任务太多导致异常退出(The application may be doing too much work on its main thread)

    今天花费了一天的时间来解决这个bug. 这种在程序运行期间出现的问题比较棘手,如果再没有规律的话就更难解决. 还好这个bug是由规律的,也就是说在程序执行半个小时左右后就会因为此异常而导致程序退出:那 ...

  4. reloadData should be in main thread

    reloadData should be called in main thread, so if you call it in work thread, you should call it as ...

  5. APP崩溃提示:This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.

    崩溃输出日志 2017-08-29 14:53:47.332368+0800 HuiDaiKe[2373:1135604] This application is modifying the auto ...

  6. Ajax.html:35 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org

    AJAX的容易错误的地方 Ajax.html:35 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated ...

  7. tensorflow_目标识别object_detection_api,RuntimeError: main thread is not in main loop,fig = plt.figure(frameon=False)_tkinter.TclError: no display name and no $DISPLAY environment variable

    最近在使用目标识别api,但是报错了: File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/script_o ...

  8. 关于chrome控制台警告:Synchronous XMLHttpRequest on the main thread

    Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to th ...

  9. iOS Main Thread Checker: UI API called on a background thread的解释

    Xcode打印栏出现如下警告: Main Thread Checker: UI API called on a background thread 这个是什么错误呢? 其实这并不一定是错误,也可以理解 ...

随机推荐

  1. 设置SVN忽略文件和文件夹(文件夹)

    在多数项目中你总会有文件和文件夹不须要进行版本号控制.这可能包含一些由编译器生成的文件,*.obj,*.lst,也许是一个用于存放可运行程序的输出文件夹.仅仅要你提交改动,TortoiseSVN 就会 ...

  2. ImageMagick的安装及使用

    近期在使用ImageMagick处理酒店团购图片,写篇博客小小的总结下它的安装及使用方法.ImageMagick是一套功能强大且免费的图片处理开发包,能够用来读,写和处理多种格式的图片文件,总之非常强 ...

  3. Hadoop-2.2.0中国文献—— MapReduce 下一代 -- 公平调度

    目的 此文档描写叙述了 FairScheduler, Hadoop 的一个可插入式的调度器.同意 YARN 应用在一个大集群中公平地共享资源. 简单介绍 公平调度是一种分配资源给应用的方法,以致到最后 ...

  4. 关于JVM的ClassLoader(转)

    众所周知,java是编译型的语言,写的是java文件,最后运行的是class文件,class文件是运行在JVM之中的,这时候就有一个问题,JVM如何装载class文件的?是通过ClassLoader来 ...

  5. WPF-20:richtextbox相关操作(转)

    WPF中的richtextbox与winform中的richtextbox的使用不同,看看下面的基本操作: 一.取出richTextBox里面的内容  (1)将richTextBox的内容以字符串的形 ...

  6. gulp快速入门

    gulp快速入门 因为之前一直有人给我推荐gulp,说他这里好哪里好的.实际上对我来说够用就行.grunt熟悉以后实际上他的配置也不难,说到效率的话如果真是要完整打包上线也不在乎那么几秒时间,对于项目 ...

  7. mahout源码KMeansDriver分析之五CIMapper

    接上文重点分析map操作: Vector probabilities = classifier.classify(value.get());// 第一行 Vector selections = pol ...

  8. Android - 通过Intent启动Activity

    通过Intent启动Activity 本文地址: http://blog.csdn.net/caroline_wendy 为了动态关联Activity界面,使用Intent启动.能够灵活绑定. 在In ...

  9. JS经常使用正則表達式【分享】

    工作中JS经常使用表达式: 1)2010-09-10类型日期校验 2)推断正整数.字符串长度 3)校验长度,和是否空 4)推断字符串是否为空 5)比較字符大小 6)推断字符串长度 7)推断格式是否为E ...

  10. 图像库---Image Datasets---OpenSift源代码---openSurf源代码

    1.Computer Vision Datasets on the web http://www.cvpapers.com/datasets.html 2.Dataset Reference http ...