一,線程和進程
????????????進程:就是一個程序從開始到結束的過程
? ? ? ? ? ? 線程:同一個應用程序中多個順序流同時執(zhí)行(比如android一個應用程序的UI用戶界面和下載同時進行)
????????單線程的運行
????????多線程的運行
二伏蚊,多線程運行模式
三痴脾,定義線程的方法
? ? ? ? 方式1,定義線程類繼承Thread并且重寫run()方法,方法run()稱為線程體(java語言只支持單線程,所以該方法定義的類不能繼承其他類)
class ?FristThread extends Thread{
????????public ?void run(){
????????????for(int i = 0;i<100;i++){
????????????????????System.out.println("FristThread--"+i);
????????}
????}?
}
class Test{
? ? public static void main(String args[]){
? ? ? ? ? ?FristThread ft = new?FristThread ();//生成線程的對象
? ? ? ? ? ? ft.start();//啟動線程
? ? ? ? ? ?// ft.run();千萬不能這樣寫
????}????
}