Skip to content

Instantly share code, notes, and snippets.

@robertoduessmann
Last active February 15, 2019 09:41
Show Gist options
  • Select an option

  • Save robertoduessmann/67840f3e7c2027b22294974b203f2978 to your computer and use it in GitHub Desktop.

Select an option

Save robertoduessmann/67840f3e7c2027b22294974b203f2978 to your computer and use it in GitHub Desktop.
public class ParalyzedFetchWeather {
private static final ForkJoinPool forkJoinPool = new ForkJoinPool();
private static final long TIMEOUT_MINUTES = 60;
private WeatherClient weatherClient;
public List<WeatherDetailsDTO> fetchWeather(List<String> cities) {
List<WeatherDetailsDTO> weathers = Collections.synchronizedList(new ArrayList<>());
cities.forEach(city -> forkJoinPool.submit(() -> weathers.add(weatherClient.getWeather(city))));
forkJoinPool.awaitQuiescence(TIMEOUT_MINUTES, TimeUnit.MINUTES);
return weathers;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment