All pastes #636161 Raw Edit

Mine

public text v1 · immutable
#636161 ·published 2007-07-27 17:50 UTC
rendered paste body
   import java.util.concurrent.*;
   import java.util.Random;
   
   
   public class UsePool {
     public static void main(String args[]) {
       Random random = new Random();
       ExecutorService executor = 
               Executors.newFixedThreadPool(3);
       // Sum up wait times to know when to shutdown
       int waitTime = 500;
       for (int i=0; i<10; i++) {
         String name = "NamePrinter " + i;
         int time = random.nextInt(1000);
         waitTime += time;
         Runnable runner = new NamePrinter(name, time);
         System.out.println("Adding: " + name + " / " + time);
         executor.execute(runner);
       }
       try {
         Thread.sleep(waitTime);
         executor.shutdown();
         executor.awaitTermination
                 (waitTime, TimeUnit.MILLISECONDS);
       } catch (InterruptedException ignored) {
       }
       System.exit(0);
     }
    }