I need to write a small program, that constantly checks if the JSON file on the server has been updated (by some other process) to report the change to the user of the program.
I'm interested in best/correct practice of doing it: how would I implement the idea of "listening" to the file-change?
So far, my idea is:
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
executor.scheduleAtFixedRate(getMessage, 0,1, TimeUnit.SECONDS);
where getMessage
is the:
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("url/get_message"))
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
message = response.body();