currentThread的一个复杂案例
生活随笔
收集整理的這篇文章主要介紹了
currentThread的一个复杂案例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
SubThread2.java
package com.dym.juc.threadmethod;public class SubThread2 extends Thread {public SubThread2() {System.out.println("構造方法中,Thread.currentThread().getName():"+Thread.currentThread().getName());System.out.println("構造方法中,this.getName():"+this.getName());}@Overridepublic void run() {System.out.println("run方法中,Thread.currentThread().getName():"+Thread.currentThread().getName());System.out.println("run方法中,this.getName():"+this.getName());} }Test02CurrentThread.java
package com.dym.juc.threadmethod;public class Test02CurrentThread {public static void main(String[] args) throws InterruptedException {SubThread2 t2 = new SubThread2();t2.setName("t2");t2.start();Thread.sleep(500);//Thread(Runnable) 構造方法形參是Runnable接口,調用時傳遞的實參是接口的實現類對象Thread t3=new Thread(t2);t3.start();} }總結
以上是生活随笔為你收集整理的currentThread的一个复杂案例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 线程的常用方法——currentThre
- 下一篇: Sharding Sphere如何配置,