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 这个是什么错误呢? 其实这并不一定是错误,也可以理解 ...
随机推荐
- linux下动态连接变为静态打包,使用statifier_S展翅飞_新浪博客
linux下动态连接变为静态打包,使用statifier_S展翅飞_新浪博客 linux下动态连接变为静态打包,使用statifier (2013-04-27 14:38:19) 转载▼
- Linux目录文件详解FHS标准(2013.09.05)
Linux 目录配置的依据FHS(Filesystem Hierarchy Standard)标准,将目录分成为四种交互作用的形态: 四种形态的具体解释: 可分享的:可以分享给其他系统挂载使用的目录, ...
- hdu3664(递推dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3664 分析:dp[i][j]表示i个数的排列中E值为j的个数.假设现在已有一个E值为j的i的排列,对于 ...
- UFLDL教程笔记及练习答案二(预处理:主成分分析和白化)
首先将本节主要内容记录下来.然后给出课后习题的答案. 笔记: :首先我想推导用SVD求解PCA的合理性. PCA原理:如果样本数据X∈Rm×n.当中m是样本数量,n是样本的维数.PCA降维的目的就是为 ...
- Redis 安装与简单示例(转)
本文转载自:http://www.cnblogs.com/kissdodog/p/3570984.html Redis的安装 Redis下载地址如下:https://github.com/dmajki ...
- The Django template language 阅读批注
The Django template language About this document This document explains the language syntax of the D ...
- VS上的WebService入门贴
由于项目需要,最近要熟悉一下通过IIS发布WebService.首先熟悉一下使用VS来创建webservice并且调用它. //------------------------------------ ...
- FMOD在Android玩音响系统的抖动问题
1. 基本介绍 在Android升级系统Android4.4之后,发现FMOD在Android音会出现抖动.导致声音不正常.边赫赫有名的"极品飞车"都有问题. 经查验,是FMOD的 ...
- Linux环境编程之同步(二):条件变量
相互排斥锁用于上锁,条件变量则用于等待.条件变量是类型为pthread_cond_t的变量.一般使用例如以下函数: #include <pthread.h> int pthread_con ...
- 基于.net开发chrome核心浏览器【二】
原文:基于.net开发chrome核心浏览器[二] 一: 上一篇的链接: 基于.net开发chrome核心浏览器[一] 二: 相关资源介绍: chrome Frame: 让IE有一颗chrome的心, ...