Thread常用方法
阿新 • • 發佈:2017-05-13
err join() eight 休眠 color int 操作 spa enter
構造方法 | 說明 |
---|---|
Thread() | 分配新的 Thread 對象 |
Thread(Runnable target) | 分配新的 Thread 對象, target 為 run() 方法被調用的對象 |
Thread(Runnable target,String name) | 分配新的 Thread 對象, target 為 run() 方法被調用的對象, name為新線程的名稱 |
void run() | 執行任務操作的方法 |
void start() | 使該線程開始執行, Java虛擬機調用該線程的 run() 方法 |
void sleep(long millis) | 在指定的毫秒數內讓當前正在執行的線程休眠(暫停方法) |
String getName() | 返回線程的名稱 |
int getPriority() | 返回線程的優先級 |
void setPriority(int newPriority) | 更改線程的優先級 |
static Thread currentThread() | 返回當前正在執行的線程對象的引用 |
boolean isAlive() | 測試線程是否處於活動狀態 |
void join() | 等待該線程終止 |
void interrupt() | 中斷線程 |
void yield() | 暫停當前正在執行的線程對象,並執行其他線程 |
Thread常用方法