Last active
February 15, 2019 09:41
-
-
Save robertoduessmann/67840f3e7c2027b22294974b203f2978 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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