日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

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

新聞中心

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

Java創(chuàng)建線程經(jīng)常在我們的編碼中出現(xiàn),當(dāng)我們?cè)谑褂玫臅r(shí)候會(huì)有不少的問(wèn)題困擾著我們。下面我們就先來(lái)了解下有關(guān)于Java創(chuàng)建線程的相關(guān)代碼希望大家有所幫助。

目前創(chuàng)新互聯(lián)已為超過(guò)千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬主機(jī)、網(wǎng)站托管、企業(yè)網(wǎng)站設(shè)計(jì)、保靖網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(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)建線程,它可安排在給定延遲后運(yùn)行命令或者定期地執(zhí)行。 ScheduledExecutorService pool = Executors.newScheduledThreadPool(2); 創(chuàng)建實(shí)現(xiàn)了Runnable接口對(duì)象,Thread對(duì)象當(dāng)然也實(shí)現(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. //將線程放入池中進(jìn)行執(zhí)行   
  7. pool.execute(t1);   
  8. pool.execute(t2);   
  9. pool.execute(t3);   
  10. //使用延遲執(zhí)行風(fēng)格的方法   
  11. pool.schedule(t4, 10, TimeUnit.MILLISECONDS);   
  12. pool.schedule(t5, 10, TimeUnit.MILLISECONDS);   
  13. //關(guān)閉線程池   
  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)建線程,它可安排在給定延遲后運(yùn)行命令或者定期地執(zhí)行。ScheduledExecutorService pool = Executors.newScheduledThreadPool(2); 創(chuàng)建實(shí)現(xiàn)了Runnable接口對(duì)象,Thread對(duì)象當(dāng)然也實(shí)現(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. //將線程放入池中進(jìn)行執(zhí)行   
  7. pool.execute(t1);   
  8. pool.execute(t2);   
  9. pool.execute(t3);   
  10. //使用延遲執(zhí)行風(fēng)格的方法   
  11. pool.schedule(t4, 10, TimeUnit.MILLISECONDS);   
  12. pool.schedule(t5, 10, TimeUnit.MILLISECONDS);   
  13. //關(guān)閉線程池   
  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  

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

【編輯推薦】

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

網(wǎng)站題目:Java創(chuàng)建線程中的代碼詳細(xì)介紹
分享鏈接:http://www.5511xx.com/article/dpoiiso.html