thead.join方法 原理
来源:互联网 发布:编程中的ret是什么意思 编辑:程序博客网 时间:2024/05/16 09:13
join方法,可以控制异步线程的执行顺序。
/** * @author zack */public class HelloJoin {public static void main(String[] args) {Thread thread1 = new Thread(new Runnable() {public void run() {System.out.println(Thread.currentThread().getName()+"-----I'm coming");}});thread1.start();try {thread1.join();} catch (InterruptedException e) {}if (thread1.isAlive()) {System.out.println(Thread.currentThread().getName() + "---I'm alive");}else{System.out.println(Thread.currentThread().getName() + "---I'm over");}System.out.println(Thread.currentThread().getName() + "--over");}}
thread1是异步线程,thread1执行完之后,main才会继续执行直到main线程结束。
Thread-0-----I'm comingmain---I'm overmain--over
源代码:
public final synchronized void join(long millis) throws InterruptedException { long base = System.currentTimeMillis(); long now = 0; if (millis < 0) { throw new IllegalArgumentException("timeout value is negative"); } if (millis == 0) { while (isAlive()) { wait(0); } } else { while (isAlive()) { long delay = millis - now; if (delay <= 0) { break; } wait(delay); now = System.currentTimeMillis() - base; } } }
原理:
阅读全文
0 0
- thead.join方法 原理
- join方法的实现原理
- hadoop mapreduce join原理、方法讲解
- RT-Thead SHELL 命令段定义实现方法
- 头部固定悬浮table表头(thead)的方法
- join方法
- join方法
- join()方法
- join()方法
- join()方法
- join()方法
- join方法
- Hash join算法原理
- Hash join算法原理
- Hash join算法原理
- Hash join算法原理
- Outer join 原理
- hive join原理
- 密码登录程序
- A7139 无线通信驱动(STM32) 增加FIFO扩展模式,可以发送超大数据包
- svm有趣的解释
- 防止图像Rect区域越界的方法
- HTTP协议详解(真的很牛逼)
- thead.join方法 原理
- MongoDB常用操作
- create table as select 和 create table 再insert into select 的差异
- SPOJ 25780 VISIBLEBOX
- 设计模式(Design pattern)
- MySQL索引使用方法和性能优化原文链接
- Android 5.0之后隐式声明Intent 启动Service引发的问题
- tensorboard 不是内部或外部命令,也不是可以运行的程序
- OneNET微信平台授课笔记