首先要明白 this.XXX 的使用場景 使用Thread.currentThread().getName()和使用this.getName()和 對象實例.getName() ,都可以得到線程的名稱,但是使用this調用getName()方法只能在本類 ...
首先要明白 this.XXX 的使用場景 使用Thread.currentThread .getName 和使用this.getName 和 對象實例.getName ,都可以得到線程的名稱,但是使用this調用getName 方法只能在本類中,而不能在其他類中,更不能在Runnable接口中,所以只能使用Thread.currentThread .getName 獲取線程的名稱,否則會出現編譯時 ...
2019-08-01 10:53 0 1235 推薦指數:
首先要明白 this.XXX 的使用場景 使用Thread.currentThread().getName()和使用this.getName()和 對象實例.getName() ,都可以得到線程的名稱,但是使用this調用getName()方法只能在本類 ...
總結起來一句話:在Thread中調用this其實就是調用Thread私有Runnable類型的target,target是Thread類的一個屬性,而Thread.currentThread()是指新New出來的實例Thread類。兩個是不同的對象。實例化一個Thread的對象,都會將其賦值 ...
,Thread.currentThread().getName()是獲得調用這個方法的線程的名字,在main線程中調用的當然是ma ...
感謝原文作者:王婷婷-Smily 原文鏈接:https://blog.csdn.net/dfshsdr/article/details/92760135 緣由 很多人認為多線程中的Thread.currentThread()和this都是顯示當前線程的意思,其實不然 ...
打印的log為: CountOperate---beginThread.currentThread().getName()=mainThread.currentThread().isAlive()=truethis.getName ...
package seday08.thread; /** * @author xingsir * 主線程 * 線程提供了一個靜態方法這個方法會將運行這個方法的線程返回:static Thread currentThread() * 一個重要的API:ThreadLocal會使 ...
重新來看多線程時,被這結果搞懵逼了。不多說,直接上代碼: Result: View Code 解析 ...
在看多線程的時候,看到這個知識點,感覺需要驗證一下。 一:線程自啟動 1.程序 測試類: 2.效果: 3.總結 Thread.currentThread():表示當前的代碼正在被誰調用。 this:只能是當前的線程,在程序中 ...