成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Java單任務延遲相關代碼的學習筆記

開發 后端
Java單任務延遲如何才能更好的使用呢?這就要求我們進行相關代碼的學習。下面就是有關于Java單任務延遲相關代碼的介紹。

Java單任務延遲連接池在四代碼基礎上,做改動,這個就需要我們不選的學習,下面我們就看看如何才能更好的使用。希望我們在下面的使用中大家更了解相關的代碼。

Java單任務延遲代碼

創建一個單線程執行程序,它可安排在給定延遲后運行命令或者定期地執行。

  1. ScheduledExecutorService pool = Executors.newSingleThread
    ScheduledExecutor(); 

 

創建一個單線程執行程序,它可安排在給定延遲后運行命令或者定期地執行。

  1. ScheduledExecutorService pool = Executors.newSingle
    ThreadScheduledExecutor();  

 

Java代碼

  1. pool-1-thread-1正在執行。。。   
  2. pool-1-thread-1正在執行。。。   
  3. pool-1-thread-1正在執行。。。   
  4. pool-1-thread-1正在執行。。。   
  5. pool-1-thread-1正在執行。。。   
  6. Process finished with exit code 0   
  7. pool-1-thread-1正在執行。。。   
  8. pool-1-thread-1正在執行。。。   
  9. pool-1-thread-1正在執行。。。   
  10. pool-1-thread-1正在執行。。。   
  11. pool-1-thread-1正在執行。。。   
  12. Process finished with exit code 0  

 

自定義線程池

Java代碼

  1. import java.util.concurrent.ArrayBlockingQueue;   
  2. import java.util.concurrent.BlockingQueue;   
  3. import java.util.concurrent.ThreadPoolExecutor;   
  4. import java.util.concurrent.TimeUnit;   
  5. /**   
  6. * Java線程:線程池-自定義線程池   
  7. *   
  8. * @author Administrator 2009-11-4 23:30:44   
  9. */   
  10. public class Test {   
  11. public static void main(String[] args) {   
  12. //創建等待隊列   
  13. BlockingQueue<Runnable> bqueue = new ArrayBlockingQueue
    <Runnable>(20);   
  14. //創建一個單線程執行程序,它可安排在給定延遲后運行命令或者定期地執行。   
  15. ThreadPoolExecutor pool = new ThreadPoolExecutor
    (2,3,2,TimeUnit.MILLISECONDS,bqueue);   
  16. //創建實現了Runnable接口對象,Thread對象當然也實現了Runnable接口   
  17. Thread t1 = new MyThread();   
  18. Thread t2 = new MyThread();   
  19. Thread t3 = new MyThread();   
  20. Thread t4 = new MyThread();   
  21. Thread t5 = new MyThread();   
  22. Thread t6 = new MyThread();   
  23. Thread t7 = new MyThread();   
  24. //將線程放入池中進行執行   
  25. pool.execute(t1);   
  26. pool.execute(t2);   
  27. pool.execute(t3);   
  28. pool.execute(t4);   
  29. pool.execute(t5);   
  30. pool.execute(t6);   
  31. pool.execute(t7);   
  32. //關閉線程池   
  33. pool.shutdown();   
  34. }   
  35. }   
  36. class MyThread extends Thread {   
  37. @Override   
  38. public void run() {   
  39. System.out.println(Thread.currentThread().getName() + 
    "正在執行。。。");   
  40. try {   
  41. Thread.sleep(100L);   
  42. } catch (InterruptedException e) {   
  43. e.printStackTrace();   
  44. }   
  45. }   
  46. }   
  47. import java.util.concurrent.ArrayBlockingQueue;   
  48. import java.util.concurrent.BlockingQueue;   
  49. import java.util.concurrent.ThreadPoolExecutor;   
  50. import java.util.concurrent.TimeUnit;   
  51.  
  52. /**   
  53. * Java線程:線程池-自定義線程池   
  54. *   
  55. * @author Administrator 2009-11-4 23:30:44   
  56. */   
  57. public class Test {   
  58. public static void main(String[] args) {   
  59. //創建等待隊列   
  60. BlockingQueue<Runnable> bqueue = new ArrayBlockingQueue
    <Runnable>(20);   
  61. //創建一個單線程執行程序,它可安排在給定延遲后運行命令或者定期地執行。   
  62. ThreadPoolExecutor pool = new ThreadPoolExecutor
    (2,3,2,TimeUnit.MILLISECONDS,bqueue);   
  63. //創建實現了Runnable接口對象,Thread對象當然也實現了Runnable接口   
  64. Thread t1 = new MyThread();   
  65. Thread t2 = new MyThread();   
  66. Thread t3 = new MyThread();   
  67. Thread t4 = new MyThread();   
  68. Thread t5 = new MyThread();   
  69. Thread t6 = new MyThread();   
  70. Thread t7 = new MyThread();   
  71. //將線程放入池中進行執行   
  72. pool.execute(t1);   
  73. pool.execute(t2);   
  74. pool.execute(t3);   
  75. pool.execute(t4);   
  76. pool.execute(t5);   
  77. pool.execute(t6);   
  78. pool.execute(t7);   
  79. //關閉線程池   
  80. pool.shutdown();   
  81. }   
  82. }   
  83. class MyThread extends Thread {   
  84. @Override   
  85. public void run() {   
  86. System.out.println(Thread.currentThread().getName() + 
    "正在執行。。。");   
  87. try {   
  88. Thread.sleep(100L);   
  89. } catch (InterruptedException e) {   
  90. e.printStackTrace();   
  91. }   
  92. }   
  93. }  

 

Java代碼

  1. pool-1-thread-1正在執行。。。   
  2. pool-1-thread-2正在執行。。。   
  3. pool-1-thread-2正在執行。。。   
  4. pool-1-thread-1正在執行。。。   
  5. pool-1-thread-2正在執行。。。   
  6. pool-1-thread-1正在執行。。。   
  7. pool-1-thread-2正在執行。。。   
  8. Process finished with exit code 0   
  9. pool-1-thread-1正在執行。。。   
  10. pool-1-thread-2正在執行。。。   
  11. pool-1-thread-2正在執行。。。   
  12. pool-1-thread-1正在執行。。。   
  13. pool-1-thread-2正在執行。。。   
  14. pool-1-thread-1正在執行。。。   
  15. pool-1-thread-2正在執行。。。  

以上就是對Java單任務延遲的相關代碼介紹。

【編輯推薦】

  1. Java線程控制權源代碼的深入探討
  2. Java線程同步引用基本代碼介紹
  3. Java線程模型如何完善相關的數據處理
  4. Java線程同步鎖解決共享數據安全
  5. Java線程檢測基本的問題猜想
責任編輯:張浩 來源: 博客園
相關推薦

2022-05-31 09:36:18

JDKDelayQueueRedis

2011-08-05 14:03:39

Objective-C 對象 模板

2024-12-31 00:00:00

RabbitMQ插件代碼

2024-12-17 15:39:33

2013-04-03 14:58:43

Android學習筆記實用代碼合集

2021-12-13 05:54:30

Windows 11操作系統微軟

2009-12-28 11:08:34

ADO 實例

2010-03-17 19:24:38

Java多線程循環

2010-03-19 16:51:53

Java Socket

2024-01-31 08:01:36

Go延遲隊列語言

2009-11-16 13:18:10

PHP上傳圖片代碼

2009-06-29 09:00:14

JSFJava

2009-06-22 14:28:00

java接口

2024-04-09 10:40:04

2024-10-22 16:39:07

2009-06-17 17:09:02

Java異常Java斷言

2024-06-05 08:09:56

2010-03-15 17:05:39

Java任務隊列

2010-07-30 13:08:38

Flex調用JavaS

2009-06-29 16:50:27

Java集合框架
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 欧美高清视频 | 91网站在线播放 | 国产精品亚洲综合 | 久久久久亚洲精品中文字幕 | 日韩av在线一区 | 亚洲天堂av在线 | 人人天天操 | 日韩免费高清视频 | 97人人干 | 水蜜桃亚洲一二三四在线 | 天堂久久久久久久 | 日韩视频在线免费观看 | 日本特黄特色aaa大片免费 | 色综合桃花网 | 中文字幕乱码一区二区三区 | 亚洲精品久久久一区二区三区 | 男女视频在线观看免费 | 狠狠久 | 国产精品日韩欧美一区二区 | 国产精品视频一二三区 | a免费视频 | 免费观看毛片 | 97视频在线观看免费 | 色综合一区二区 | 精品国产一区二区三区在线观看 | 久久国产视频网站 | 成人精品一区二区三区中文字幕 | 高清av一区| 欧美成人在线免费 | 91天堂| 97成人免费 | 麻豆av片| 久草在线青青草 | 久久美女网| 99爱视频| 国产特级毛片aaaaaa | 午夜视频一区二区三区 | 亚洲一区二区久久 | 国外成人在线视频网站 | 亚洲精品二区 | 夜夜久久 |