Advertisement
Guest User

Untitled

a guest
May 24th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1.         List<Filial> filialsByCity = new CopyOnWriteArrayList<>();
  2.  
  3.         ExecutorService executorService = Executors.newFixedThreadPool(Location.SIBERIAN_DISTRICT.size());
  4.         List<Future> futures = new ArrayList<>();
  5.  
  6.         for (String city : Location.SIBERIAN_DISTRICT) {
  7.             Future future = executorService.submit(new Thread(() -> {
  8.                 Filial filial = twoGisWorkerService.getFilialByCity(fieldOfActivity, city);
  9.                 if (filial.getRating() > 0) {
  10.                     filialsByCity.add(filial);
  11.                 }
  12.             }));
  13.             futures.add(future);
  14.         }
  15.  
  16.  
  17.         for (Future f : futures) {
  18.             try {
  19.                 f.get();
  20.             } catch (InterruptedException e) {
  21.                 e.printStackTrace();
  22.             } catch (ExecutionException e) {
  23.                 e.printStackTrace();
  24.             }
  25.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement