日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Java創(chuàng)建線程中的代碼詳細介紹

Java創(chuàng)建線程經(jīng)常在我們的編碼中出現(xiàn),當我們在使用的時候會有不少的問題困擾著我們。下面我們就先來了解下有關于Java創(chuàng)建線程的相關代碼希望大家有所幫助。

目前創(chuàng)新互聯(lián)已為超過千家的企業(yè)提供了網(wǎng)站建設、域名、虛擬主機、網(wǎng)站托管、企業(yè)網(wǎng)站設計、保靖網(wǎng)站維護等服務,公司將堅持客戶導向、應用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

 
 
 
  1. import java.util.concurrent.Executors;   
  2. import java.util.concurrent.ScheduledExecutorService;   
  3. import java.util.concurrent.TimeUnit;   
  4. /**   
  5. * Java線程:線程池-   
  6. *   
  7. * @author Administrator 2009-11-4 23:30:44   
  8. */   
  9. public class Test {   
  10. public static void main(String[] args) {  

Java創(chuàng)建線程,它可安排在給定延遲后運行命令或者定期地執(zhí)行。 ScheduledExecutorService pool = Executors.newScheduledThreadPool(2); 創(chuàng)建實現(xiàn)了Runnable接口對象,Thread對象當然也實現(xiàn)了Runnable接口

 
 
 
  1. Thread t1 = new MyThread();   
  2. Thread t2 = new MyThread();   
  3. Thread t3 = new MyThread();   
  4. Thread t4 = new MyThread();   
  5. Thread t5 = new MyThread();   
  6. //將線程放入池中進行執(zhí)行   
  7. pool.execute(t1);   
  8. pool.execute(t2);   
  9. pool.execute(t3);   
  10. //使用延遲執(zhí)行風格的方法   
  11. pool.schedule(t4, 10, TimeUnit.MILLISECONDS);   
  12. pool.schedule(t5, 10, TimeUnit.MILLISECONDS);   
  13. //關閉線程池   
  14. pool.shutdown();   
  15. }   
  16. }   
  17. class MyThread extends Thread {   
  18. @Override   
  19. public void run() {   
  20. System.out.println(Thread.currentThread().getName() + "正在執(zhí)行。。。");   
  21. }   
  22. }   
  23. import java.util.concurrent.Executors;   
  24. import java.util.concurrent.ScheduledExecutorService;   
  25. import java.util.concurrent.TimeUnit;   
  26. /**   
  27. * Java線程:線程池-   
  28. *   
  29. * @author Administrator 2009-11-4 23:30:44   
  30. */   
  31. public class Test {   
  32. public static void main(String[] args) {  

Java創(chuàng)建線程,它可安排在給定延遲后運行命令或者定期地執(zhí)行。ScheduledExecutorService pool = Executors.newScheduledThreadPool(2); 創(chuàng)建實現(xiàn)了Runnable接口對象,Thread對象當然也實現(xiàn)了Runnable接口

 
 
 
  1. Thread t1 = new MyThread();   
  2. Thread t2 = new MyThread();   
  3. Thread t3 = new MyThread();   
  4. Thread t4 = new MyThread();   
  5. Thread t5 = new MyThread();   
  6. //將線程放入池中進行執(zhí)行   
  7. pool.execute(t1);   
  8. pool.execute(t2);   
  9. pool.execute(t3);   
  10. //使用延遲執(zhí)行風格的方法   
  11. pool.schedule(t4, 10, TimeUnit.MILLISECONDS);   
  12. pool.schedule(t5, 10, TimeUnit.MILLISECONDS);   
  13. //關閉線程池   
  14. pool.shutdown();   
  15. }   
  16. }   
  17. class MyThread extends Thread {   
  18. @Override   
  19. public void run() {   
  20. System.out.println(Thread.currentThread().getName() + "正在執(zhí)行。。。");   
  21. }   
  22. } Java代碼   
  23. pool-1-thread-1正在執(zhí)行。。。   
  24. pool-1-thread-2正在執(zhí)行。。。   
  25. pool-1-thread-1正在執(zhí)行。。。   
  26. pool-1-thread-1正在執(zhí)行。。。   
  27. pool-1-thread-2正在執(zhí)行。。。   
  28. Process finished with exit code 0  

以上就是對Java創(chuàng)建線程的詳細介紹,希望大家有所收獲。

【編輯推薦】

  1. Java線程同步如何在不同線程中調用
  2. Java線程同步的優(yōu)先級介紹
  3. Java線程返回值如何控制自己的未來
  4. Java線程通信源代碼中的奧秘探究
  5. Java線程控制權源代碼的深入探討

文章標題:Java創(chuàng)建線程中的代碼詳細介紹
文章網(wǎng)址:http://www.dlmjj.cn/article/dpoiiso.html