Advertisement
sizhkibezkoli

Untitled

Dec 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. @Override
  2.     public StatisticResult call() {
  3.         ExecutorService executor = Executors.newFixedThreadPool(4);
  4.  
  5.         Drop drop = new Drop();
  6.         Random random = new Random();
  7.         StatisticWorker statictic = new StatisticWorker(drop);
  8.         Producer producer = new Producer(drop);
  9.  
  10.         executor.submit(producer);
  11.         Future<StatisticResult> result = executor.submit(statictic);
  12.  
  13.         PrintWorker printWorker = new PrintWorker(statictic.getStatistic());
  14.         executor.submit(printWorker);
  15.  
  16.         for (int i = 0; i < 500; i++) {
  17.             executor.submit(new Consumer(drop));
  18.             sleep(random);
  19.         }
  20.  
  21.         printWorker.stop();
  22.         producer.stop();
  23.         statictic.stop();
  24.         executor.shutdown();
  25.  
  26.         return getResult(result);
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement