Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2222

how to avoid while loop while waiting for future complete?

$
0
0

I have a problem with a java future and an handler function. code example:

public HealthCheckResponse call() {  String redisHost = this.configuration.getRedisHost();  log.info("connect to redis host: {}", redisHost);  Future<RedisConnection> redisConnectionFuture = Redis.createClient(Vertx.vertx(), redisHost).connect();        while (!redisConnectionFuture.isComplete()) {            log.debug("waiting for redis connection future complete: ({})", redisConnectionFuture.isComplete());        }        log.info("redis connection future completed, {} and succeded {}", redisConnectionFuture.isComplete(), redisConnectionFuture.succeeded());        if (redisConnectionFuture.isComplete() && redisConnectionFuture.succeeded()) {            return HealthCheckResponse.up("RedisCustomHealthCheck");        }        log.info("sending down RedisCustomHealthCheck");        return HealthCheckResponse.down("RedisCustomHealthCheck");    }

so my problem is that I have to check the redis connection. This is an async function so, I can set onSuccess and write my logic. there I can not return the HealtCheckResponse. Question, I don't want to wait with the while loop. What is a possible solution for this problem?


Viewing all articles
Browse latest Browse all 2222


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>