SHARE
TWEET

multithreading

mrityunjay2002 Oct 16th, 2011 46 Never
  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.  
RAW Paste Data
Top