使用Java 8运行CompletableFuture方法时出现的问题

时间:2019-05-09 22:11:11

标签: java spring-boot asynchronous completable-future spring-async

我有一个spring boot应用程序,我用jhispter生成了该应用程序,我有一个spring服务,该服务具有如下调度方法:

@Scheduled(cron = "0 0/2 * * * *")
private void checkStatusRouters() {

    if(!IS_JOB_RUNNING){
        IS_JOB_RUNNING =true;
        log.info("[JOB-MONITOR] - Initializing scan", Instant.now());
        List<MicroTikRouter> routers = routerService.findAllEntities();
        log.info("Roteadores encontrados: {}",routers.size());
        for (MicroTikRouter router : routers) {
            try {
                log.info("Iniciando roteador : {}", router.getDescription());
                CompletableFuture<Boolean> check =  routerService.checkRouterStatusAsync(router);
                check.exceptionally(exception -> {
                    //HandleException
                });
            }
            catch(Exception ex){
                //Handle
            }
        }
}   }

此方法多次调用下面描述的routerService.checkRouterStatusAsync()。 (我不必等待此方法的结果)

@Async
public CompletableFuture<Boolean> checkRouterStatusAsync(MicroTikRouter router) throws  ApiConnectionException,ApiCommandException,Exception {

    //neither this log is appearing
    log.info("Request print router {} : with ip/dns  {} ",router.getCode(),router.getIp());

    //make many things  

    return CompletableFuture.completedFuture(true);
}   

奇怪的是,日志checkRouterStatusAsync上没有任何内容。

那只发生在我的生产服务器上,它在本地有效。在两侧(本地和生产环境),我都安装了Java 8。

我使用命令java -jar {myPackage}.war运行我的应用程序。

有人可以帮助我吗?

0 个答案:

没有答案
相关问题