main thread starting…
例的结果,下面的:
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…的更多相关文章
- jupyter notebook中出现ValueError: signal only works in main thread 报错 即 长时间in[*] 解决办法
我在jupyter notebook中新建了一个基于py3.6的kernel用来进行tensorflow学习 但是在jupyter notebook中建立该kernel时,右上角总是显示 服务正在启动 ...
- 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 ...
- 13、主线程任务太多导致异常退出(The application may be doing too much work on its main thread)
今天花费了一天的时间来解决这个bug. 这种在程序运行期间出现的问题比较棘手,如果再没有规律的话就更难解决. 还好这个bug是由规律的,也就是说在程序执行半个小时左右后就会因为此异常而导致程序退出:那 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 关于chrome控制台警告:Synchronous XMLHttpRequest on the main thread
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to th ...
- iOS Main Thread Checker: UI API called on a background thread的解释
Xcode打印栏出现如下警告: Main Thread Checker: UI API called on a background thread 这个是什么错误呢? 其实这并不一定是错误,也可以理解 ...
随机推荐
- hdu1054(最小顶点覆盖)
传送门:Strategic Game 题意:用尽量少的顶点来覆盖所有的边. 分析:最小顶点覆盖裸题,最小顶点覆盖=最大匹配数(双向图)/2. #include <cstdio> #incl ...
- C语言 - 结构体(struct)比特字段(:) 详细解释
结构体(struct)比特字段(:) 详细解释 本文地址: http://blog.csdn.net/caroline_wendy/article/details/26722511 结构体(struc ...
- hdu 4739【位运算】.cpp
题意: 给出n个地雷所在位置,正好能够组成正方形的地雷就可以拿走..为了简化题目,只考虑平行于横轴的正方形.. 问最多可以拿走多少个正方形.. 思路: 先找出可以组成正方形的地雷组合cnt个.. 然后 ...
- POJ 1018 【枚举+剪枝】.cpp
题意: 给出n个工厂的产品参数带宽b和价格p,在这n个工厂里分别选1件产品共n件,使B/P最小,其中B表示n件产品中最小的b值,P表示n件产品p值的和. 输入 iCase n 表示iCase个样例n个 ...
- BASH Shell 简易进度条小函数
不多说,直接上脚本. # processbar <current> <total> processbar() { local current=$1; local total=$ ...
- Python使用时间戳
1.将字符串的时间转换为时间戳 方法: a = "2013-10-10 23:40:00" 将其转换为时间数组 importtime timeArray = time.strpti ...
- SVNKIT的low api应用之修改库中文件内容(File modification)
最近在做一个仓库管理系统,架构在svn之上.要求每一项操作要记录在log文件中,弄了很久起初感觉无法向库中的文本文件添加东西,就是修改库中的文本文件.于是采用了一个很笨的办法: 现将库中的log ...
- oracle ebs 12.20 安装成功其过程失败日记及总结(1)
由于公司业务须要,须要安装oracle ebs进行 form 开发,所以就開始了痛苦oracle ebs安装之过程.刚開始是在vm中win2003 server 中安装ebs,,不知是我自已的水平太差 ...
- 【DRP】删除递归树的操作
正如图呈现的树结构.本文从任意节点删除树形结构.提供解决方案 图中,不包括其他结点的是叶子结点.包括其他结点的是父结点,即不是叶子结点. 一 本文的知识点: (1)递归调用: 由于待删除的结点的层次是 ...
- ecshop 调用其他数据库中的商品
ecshop中修改includes/cls_ecshop.php中第53行 function table($str) { /* if($str=='goods'){ return '`ecshop3' ...