main thread starting…
来源:互联网 发布:windows的桌面是指 编辑:程序博客网 时间:2024/06/04 19:19
运行结果如下:
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…
- Starting elasticsearch: Exception in thread "main" java.lang.IllegalStateException: Could not load p
- Main Thread & UI Thread
- main Queue 与 main Thread
- Android UI thread / main thread
- Android UI thread / main thread
- baber main thread barber thread
- Java Thread Programming 1.3 - Creating and Starting a Thread
- main thread in android application
- Exception in thread "main" AxisFault
- How the Main Thread works
- RT-thread main函数分析
- Thread starting during runtime shutdown问题的解决
- java.lang.InternalError: Thread starting during runtime shutdown
- 1.1.3开启线程(Starting a Thread)
- java.lang.InternalError: Thread starting during runtime shutdown
- STARTING
- STARTING
- vim常用命令
- 设计模式 - 状态模式(state pattern) 详解
- 如何jpg和png混和使用,实现mask?
- spring mvc 入门学习(一)
- 啥地方地方三顿饭
- main thread starting…
- QT的元类型和QT线程通信的方法
- 让overflow始终显示在actiongBar上
- main函数的运行
- 对于对象查询
- GDB
- Spring3.1 Cache注解
- HBuilder真机联调教程:iPhone/Android联调失败?
- Mapreduce shuffle和排序