国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

API解讀:Thread

2019-11-17 06:18:11
字體:
供稿:網(wǎng)友

線程是一個和平臺關(guān)系比較密切的概念,這里我們也不能看出它的具體實現(xiàn),只能看一下它的表現(xiàn)了.

public class Thread implements Runnable

public final static int MIN_PRIORITY = 1;
public final static int NORM_PRIORITY = 5;
public final static int MAX_PRIORITY = 10;
//以上三個是表示線程的優(yōu)先級的,默認的都是和父線程具有相同的優(yōu)先級
public static native Thread currentThread();
//獲得當(dāng)前運行線程的線程實例,注重這是個靜態(tài)方法
public static native void yield();
//當(dāng)前線程主動放棄執(zhí)行,讓其他線程可以運行,這個是雷鋒精神
public static native void sleep(long millis) throws InterruptedException;
//當(dāng)前線程自己休眠一會兒,過了這段時間后重新回到可執(zhí)行狀態(tài),有時候為了等別人就自己先睡一會兒
//不過這一覺睡多長時間是比較難確定的
public static void sleep(long millis, int nanos) throws InterruptedException
//這個方法有點多余,把后面的納秒四舍五入而已,最終的效果或者是sleep(millis)和sleep(millis+1).

構(gòu)造函數(shù)
public Thread();
public Thread(Runnable target)//這個是最常用的構(gòu)造函數(shù)
public Thread(ThreadGroup group, Runnable target)//不是很關(guān)心輸入哪個線程組
public Thread(String name) //我們似乎不關(guān)心線程的名字
public Thread(ThreadGroup group, String name)
public Thread(Runnable target, String name)
public Thread(ThreadGroup group, Runnable target, String name)
public Thread(ThreadGroup group, Runnable target, String name,long stackSize)
public synchronized native void start();
//運行線程用start方法,不知道里面怎么實現(xiàn)了,不過會調(diào)用run方法
public void run() {
if (target != null) {
target.run();
}
}
可以看出,假如沒有target參數(shù),這個線程什么也不做.

//下面幾個方法已經(jīng)不用了,我也不是很清楚為什么,也不用去管這個了.
public final void stop()
public final synchronized void stop(Throwable obj)
public final void suspend()
public final void resume()


public void interrupt()
//中斷這個線程,這個方法除了設(shè)置中斷狀態(tài)位,不知道還做了什么

public static boolean interrupted() {
return currentThread().isInterrupted(true);
}
//是否被中斷,重置中斷狀態(tài)
public boolean isInterrupted() {
return isInterrupted(false);
}
//是否被中斷
private native boolean isInterrupted(boolean ClearInterrupted);

public void destroy() {
throw new NoSUChMethodError();
}
public final native boolean isAlive();
//線程是否還活著,出生了但還沒死


public final void setPriority(int newPriority)
public final void setName(String name)
public final String getName()
public final ThreadGroup getThreadGroup()
public static int activeCount() //獲得當(dāng)前線程組獲得線程數(shù)
public static int enumerate(Thread tarray[]) //將活動線程拷貝到一個數(shù)組
public native int countStackFrames();
public final synchronized void join(long millis) throws InterruptedException//等待這個線程死,這個家伙沒有耐心,過了一段時間就不等了.
public final synchronized void join(long millis, int nanos) throws InterruptedException //沒什么用的方法
 public final void join() throws InterruptedException //這個家伙很有耐心,為了拿遺產(chǎn),一直等著他老爸死才肯罷休.

public final void setDaemon(boolean on)
public final boolean isDaemon()
public final void checkaccess() //這個似乎不應(yīng)該public
public String toString()


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 宿迁市| 神木县| 永定县| 阿克| 安溪县| 象州县| 金山区| 东阿县| 日土县| 浮山县| 海原县| 萨嘎县| 东台市| 青川县| 连云港市| 霍林郭勒市| 益阳市| 桃江县| 辛集市| 宁阳县| 拜城县| 卢龙县| 鄂托克旗| 梁山县| 遂川县| 南昌县| 酉阳| 蒲城县| 内江市| 将乐县| 大悟县| 贵州省| 盐亭县| 凤台县| 南丰县| 台中县| 永泰县| 邹平县| 大石桥市| 五华县| 嘉鱼县|