Create a gist now

Instantly share code, notes, and snippets.

@anataliocs / Secret
Last active Jan 23, 2018

What would you like to do?
Spring Scheduled task background process to make async call to update cache
public class Application {
public static void main(String[] args) {, args);
public class ScheduledTask {
private static final long RUN_TASK_EVERY_10_SEC = 10000l;
private static final long SLEEP_1_SEC = 1000L;
private final Logger logger = LoggerFactory.getLogger(ScheduledTask.class);
Service service;
@Scheduled(fixedDelay = RUN_TASK_EVERY_10_SEC)
public void updateEndpoints() {
Future<Map<String, String>> status =
while (!(status.isDone()) {
logger.trace("Do Action here");
public class ServiceImpl implements Service {
public Future<Map<String, String>> getEndpointStatus(int serviceName) {
switch (serviceName) {
case :
return getStatus();
private Future<Map<String, String>> getStatus() {
return new AsyncResult<Map<String, String>>(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment