av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

初學(xué)Java多線程:使用Runnable接口創(chuàng)建線程

實(shí)現(xiàn)Runnable接口的類必須使用Thread類的實(shí)例才能創(chuàng)建線程。通過(guò)Runnable接口創(chuàng)建線程分為兩步:

1. 將實(shí)現(xiàn)Runnable接口的類實(shí)例化。

2.     建立一個(gè)Thread對(duì)象,并將第一步實(shí)例化后的對(duì)象作為參數(shù)傳入Thread類的構(gòu)造方法。

   最后通過(guò)Thread類的start方法建立線程。

下面的代碼演示了如何使用Runnable接口來(lái)創(chuàng)建線程:

 
 
 
  1. package mythread;  
  2.  
  3. public class MyRunnable implements Runnable  
  4. {  
  5.     public void run()  
  6.     {  
  7.         System.out.println(Thread.currentThread().getName());  
  8.     }  
  9.     public static void main(String[] args)  
  10.     {  
  11.         MyRunnable t1 = new MyRunnable();  
  12.         MyRunnable t2 = new MyRunnable();  
  13.         Thread thread1 = new Thread(t1, "MyThread1");  
  14.         Thread thread2 = new Thread(t2);  
  15.         thread2.setName("MyThread2");  
  16.         thread1.start();  
  17.         thread2.start();  
  18.     }  
  19. }  

上面代碼的運(yùn)行結(jié)果如下:

MyThread1
MyThread2

舉例Java多線程的學(xué)習(xí)又更近一步了。

【編輯推薦】

  1. 初學(xué)Java多線程:用Thread類創(chuàng)建線程
  2. 初學(xué)Java多線程:線程簡(jiǎn)介
  3. Java多線程編程的常見陷阱
  4. Java多線程的相關(guān)機(jī)制
  5. Java多線程學(xué)習(xí)總結(jié)(二)

網(wǎng)頁(yè)題目:初學(xué)Java多線程:使用Runnable接口創(chuàng)建線程
分享網(wǎng)址:http://uogjgqi.cn/article/coeddch.html
掃二維碼與項(xiàng)目經(jīng)理溝通

我們?cè)谖⑿派?4小時(shí)期待你的聲音

解答本文疑問(wèn)/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流