Want more features on Pastebin? Sign Up, it's FREE!
Guest

multithreading

By: mrityunjay2002 on Oct 16th, 2011  |  syntax: Java 5  |  size: 0.54 KB  |  views: 40  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  public static List<Item> parse() {
  2.         CountDownLatch latch = new CountDownLatch(1000);
  3.         for (int i = 1; i <= 1000; i++) {
  4.             Executor executor = Executors.newFixedThreadPool(20);
  5.             Parser thread = new Parser(latch);
  6.             thread.setName(Integer.toString(i));
  7.             threadCount++; //increase the number of working threads
  8.             executor.submit(thread);            
  9.         }
  10.         latch.await();
  11.         return itemList;
  12. }
  13.  
  14. public void run() {
  15.         // jsut add the line after you code
  16.         latch.countDown();
  17. }
  18.  
clone this paste RAW Paste Data