this与Thread.currentThread
来源:互联网 发布:云计算和软件工程区别 编辑:程序博客网 时间:2024/06/06 03:17
this指代new TestJoin(),而currentThread()指代new Thread(new TestJoin())
public class TestJoin implements Runnable { public static void main(String[] sure) throws InterruptedException { Thread t = new Thread(new TestJoin()); long start = System.currentTimeMillis(); t.start(); t.join(1000);//等待线程t 1000毫秒 System.out.println(System.currentTimeMillis()-start);//打印出时间间隔 System.out.println("Main finished");//打印主线程结束 } @Override public void run() {//理解这里为何不用this关键字,this指代new TestJoin(),而currentThread()指代new Thread(new TestJoin()) synchronized (Thread.currentThread()) { for (int i = 1; i <= 5; i++) { try { TimeUnit.SECONDS.sleep(1);//睡眠5秒,循环是为了方便输出信息 } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("睡眠" + i); } System.out.println("TestJoin finished");//t线程结束 } }}
阅读全文
0 0
- this与Thread.currentThread
- Thread.CurrentThread.getName 与 this.getName()
- Thread.currentThread()与this的区别
- java--this与Thread.currentThread()区别
- Thread.currentThread()与this的区别
- Thread.currentThread()与this的区别
- Thread.currentThread().getName()与this.getName()的区别
- JAVA 多线程 this.getName()与Thread.currentThread().getName()
- Java多线程--详解this与Thread.currentThread()的区别
- 多线程中this、Thread.currentThread()和this.currentThread()的区别
- Thread.currentThread().getName() 和 this.getName()详解
- this和Thread.currentThread的区别
- 多线程this.getName()和Thread.currentThread().getName()
- Thread.sleep 与Thread.currentThread.sleep
- java多线程中this与Thread.currentThread()返回值的引用问题
- java多线程中this与Thread.currentThread()返回值的引用问题
- java多线程中this与Thread.currentThread()返回值的引用问题
- Java多线程之this与Thread.currentThread()的区别——java多线程编程核心技术
- csu-1216: 异或最大值
- tomcat日志报错Could not find or load main class org.apache.catalina.startup.Bootstrap
- 线程同步:CRITICAL_SECTION, Mutex , Event
- HDU 1176 免费馅饼
- 数据库中截取字符串的简单方法
- this与Thread.currentThread
- 关于双向回呼系统
- HDU 1754(线段树,单点覆盖 询问区间最值)
- 爬虫requests对post的使用方法
- 神经网络中的难点及解决方案
- 【模板】【数据结构】并查集(路径压缩+按秩合并)
- 单链表的操作集合
- php文件上传
- MySQL 查询所有表名