实测

您所在的位置:网站首页 如何将u盘中的系统安装到电脑里 实测

实测

2024-07-16 21:48| 来源: 网络整理| 查看: 265

JAVA 多线程 this.getName()与Thread.currentThread().getName()

hansonzhe 回复 hansonzhe: [code=java] public static void main(String a[]) throws InterruptedException { Student S0 = new CurrentThreadTest(). new Student("Jack"); Thread T0 = new Thread(S0); System.out.println("S0.getName " + S0.getName()); System.out.println("T0.getName " + T0.getName()); Thread.sleep(1000); // currentThread() 是 T0,this.getName() 是 S0 System.out.println("T0.start();"); T0.start(); Thread.sleep(1000); // currentThread() 是 S0,this.getName() 是 S0 System.out.println("S0.start();"); S0.start(); Thread.sleep(1000); // 不会执行 System.out.println("T0.run();"); T0.run(); Thread.sleep(1000); // currentThread() 是 main,this.getName() 是 S0 System.out.println("S0.run();"); S0.run(); Thread.sleep(1000); } } [/code] 执行这段代码,会很清晰看出 Thread.currentThread().getName() 和 this.getName() 的区别。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3