Manage java thread pool and build distributed Hadoop scheduling framework

From , 3 Years ago, written in Java, viewed 52 times.
URL https://pastebin.vip/view/b20bb95a
  1. package thread;
  2. import java.util.Vector;
  3. import java.util.concurrent.CountDownLatch;
  4. public class MultiThread extends Thread {    
  5. static Vector<Integer>
  6. list = new Vector<Integer>(100);    
  7. static CountDownLatch count = new CountDownLatch(10);    
  8. public void run() {          
  9. while (list.size() > 0) {              
  10. try {                    
  11. int val = list.remove(0);                    
  12. System.out.println(val);                    
  13. Thread.sleep(100);//模拟处理               }
  14. catch (Exception e) {                    // 可能数组越界,这个地方只是为了说明问题,忽略错误               }          }                  
  15. count.countDown(); // 删除成功减一     }    
  16. public static void main(String[] args) throws InterruptedException {                  
  17. for (int i = 0; i < 100; i++) {              
  18. list.add(i);          }                  
  19. long start = System.currentTimeMillis();          
  20. for (int i = 0; i < 10; i++) {              
  21. new MultiThread().start();          }                  
  22. count.await();          
  23. long end = System.currentTimeMillis();          
  24. System.out.println("消耗 " + (end - start) + " ms");     }     // 消耗 1001 ms}//源代码片段来自云代码http://yuncode.net
  25.                        

Reply to "Manage java thread pool and build distributed Hadoop scheduling framework"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website