#402 Caching Forecasts for a High-Load Endpoint
-
There is an
aiWeatherForecastfunction that calculates the temperature through a neural network in approximately one second. -
There is a high-load
/weatherendpoint handling 10k RPS. The endpoint callsgetWeatherForecastto obtain the forecast.
Optimize getWeatherForecast for high load:
public class WeatherForecaster {
public int getWeatherForecast() throws InterruptedException {
// TODO optimize the method for high load
return aiWeatherForecast();
}
private int aiWeatherForecast() throws InterruptedException {
Thread.sleep(1000);
return new Random().nextInt(70) - 30;
}
}
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor