Thread.currentThread()与this的区别【待完善】
区别 this thread 完善
2023-09-14 09:13:18 时间
Thread.currentThread()与this的区别【待完善】
package grammar.Thread.Chapter1;
public class CountOperate extends Thread {
public CountOperate(){
System.out.println("CountOperate - begin");
System.out.println("Thread.getCurrentThread().getName() = " + Thread.currentThread().getName());
System.out.println("Thread.getCurrentThread().isAlive() = " + Thread.currentThread().isAlive());
System.out.println("Thread.currentThread().getClass() = "+Thread.currentThread().getClass()+"\n\n");
System.out.println("this.getName() = " + this.getName());
System.out.println("this.isAlive() = " + this.isAlive());
System.out.println("this.getClass() is = "+this.getClass());
System.out.println("CountOperate - end\n\n");
}
@Override
public void run() {
System.out.println("run - begin");
System.out.println("Thread.getCurrentThread().getName() = " + Thread.currentThread().getName());
System.out.println("Thread.getCurrentThread().isAlive() = " + Thread.currentThread().isAlive());
System.out.println("Thread.currentThread().getClass() = "+Thread.currentThread().getClass()+"\n\n");
System.out.println("this.getName() = " + this.getName());
System.out.println("this.getClass() is = "+this.getClass());
System.out.println("this.isAlive() = " + this.isAlive());
System.out.println("run - end\n\n");
}
}
package grammar.Thread.Chapter1;
public class Test {
public static void main(String[] args) {
CountOperate c = new CountOperate();
Thread t1 = new Thread(c);
System.out.println("Main begin t1 isAlive = " + t1.isAlive());
t1.setName("A");
t1.start();
System.out.println("Main end t1 isAlive = "+ t1.isAlive());
}
}
执行结果如下:
CountOperate - begin
Thread.getCurrentThread().getName() = main
Thread.getCurrentThread().isAlive() = true
Thread.currentThread().getClass() = class java.lang.Thread
this.getName() = Thread-0
this.isAlive() = false
this.getClass() is = class grammar.Thread.Chapter1.CountOperate
CountOperate - end
Main begin t1 isAlive = false
Main end t1 isAlive = true
run - begin
Thread.getCurrentThread().getName() = A
Thread.getCurrentThread().isAlive() = true
Thread.currentThread().getClass() = class java.lang.Thread
this.getName() = Thread-0
this.getClass() is = class grammar.Thread.Chapter1.CountOperate
this.isAlive() = false
run - end
相关文章
- jar和war的区别
- form layui vue 和_layui和vue的区别是什么?[通俗易懂]
- git和github gitlab的区别_gitlab和git区别
- tkmapper教程_tkr和tka的区别
- synchronized(this)、synchronized(.class)、锁静态方法、方法区别?
- js中this指向问题及call,apply,bind的区别
- PHP 中 call_user_func 函数 和 call_user_func_array 函数的区别
- ABAP:区别CALL SCREEN/SET SCREEN/LEAVE TO SCREEN详解编程语言
- CK44和CKR1的区别详解编程语言
- 的区别MySQL中的与或:区别深浅(mysql与或)
- Linux修改内容命令:轻松编辑文件!Note: This is an AIgenerated article not a humanwritten one. Please take this into account when reading it.(linux修改内容命令)
- MySQL数据库中的不等于符号和地址符号的区别(mysql不等于地址)
- 语句区别Oracle两个Case语句的不同之处(oracle两个case)
- 终于了解了下.net和j2ee的区别
- DivCSSabsolute与relative的区别小结
- 基于request.getAttribute与request.getParameter的区别详解