前面大致的了解了Thread的一些方法和屬性下面對(duì)一些方法進(jìn)行運(yùn)用看看具體效果<下面可能還是會(huì)貼很多的源代碼,其實(shí)我是拒絕的,我只想貼每個(gè)方法的代碼,但是有時(shí)候看到一個(gè)方法里面有調(diào)用了方法,但是筆者有沒(méi)有給出來(lái),很蛋疼,有種爽到一半的感覺(jué),所以我還是會(huì)把它貼出來(lái),希望一次就能挖到底,不論有沒(méi)有全懂,但至少懂了幾分。>
activeCount():返回當(dāng)前線程所屬線程組的活動(dòng)線程數(shù)
源代碼如下:
1 /** 2 * Returns an estimate of the number of active threads in the current 3 * thread's {@linkplain java.lang.ThreadGroup thread group} and its 4 * subgroups. Recursively iterates over all subgroups in the current 5 * thread's thread group. 6 * 7 * <p> The value returned is only an estimate because the number of 8 * threads may change dynamically while this method traverses internal 9 * data structures, and might be affected by the presence of certain10 * system&