1. 程式人生 > 遊戲攻略 >《幻塔》危險入侵採集物品攻略

《幻塔》危險入侵採集物品攻略

Thread.currentThread()

package com.alanliu.Java8BasicCodeStuding.Java8BasciCode.Unit11_Thread.CreateThreadDemo;
/**
 * 多執行緒 實現:
 * 
 * 1:基於主執行緒獲取對其的引用。 Thread t = Thread.currentThread();
 * 2:implements 實現 Runnable 介面 
 * 3:extends 繼承 Thread 類的方法。
 * 
 * Thread類的方法:
 * getName()   獲取執行緒的名稱
 * getPriority() 獲取執行緒的優先順序
 * isAlive()  確定執行緒是否仍然在執行
 * join()  等待執行緒終止
 * run()  執行緒的入口點
 * sleep() 掛起執行緒一段時間
 * start()  通過呼叫執行緒的run()方法啟動執行緒。
 * 、
 * 
 * 
 * 
@author develop * */ class CurrentThreadDemo { public static void main(String args[]) { /** * 主執行緒: * 1:其重要2的因素: * 1-1:其他子執行緒都是從主執行緒產生的 * 1-2:通常,主執行緒必須是最後才結束執行的執行緒。 * * 儘管主執行緒是在程式啟動時自動建立的,但是可以通過Thread 物件對其進行控制。為此, * 必須呼叫currentThread()方法獲取對主執行緒的一個引用。該方法是Thread的一個共有靜態成員,它的一般形式如下: * static Thread currentThread()
*/ Thread t = Thread.currentThread(); System.out.println("Current thread: " + t); // change the name of the thread t.setName("My Thread"); System.out.println("After name change: " + t); try { for(int n = 5; n > 0; n--) { System.out.println(n); Thread.sleep(
1000); } } catch (InterruptedException e) { System.out.println("Main thread interrupted"); } } /** * 執行結果: * Current thread: Thread[main,5,main] After name change: Thread[My Thread,5,main] 5 4 3 2 1 */ }

為人:謙遜、激情、博學、審問、慎思、明辨、 篤行
學問:紙上得來終覺淺,絕知此事要躬行
為事:工欲善其事,必先利其器。
態度:道阻且長,行則將至;行而不輟,未來可期
轉載請標註出處!