From 0e95588c540f92bfce03c39a174bad4bd86b7055 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Wed, 11 Apr 2018 12:20:03 +0200 Subject: [PATCH] Refactor (#3923) * NatsClient refactor * Use lambda --- .../java/com/baeldung/shutdown/Application.java | 9 +++------ .../ExecutorServiceExitCodeGenerator.java | 17 ++++++++--------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/spring-boot/src/main/java/com/baeldung/shutdown/Application.java b/spring-boot/src/main/java/com/baeldung/shutdown/Application.java index 964e092c10..3d9c71a7b9 100644 --- a/spring-boot/src/main/java/com/baeldung/shutdown/Application.java +++ b/spring-boot/src/main/java/com/baeldung/shutdown/Application.java @@ -34,12 +34,9 @@ public class Application { ConfigurableApplicationContext ctx = new SpringApplicationBuilder(Application.class).web(false).run(); - int exitCode = SpringApplication.exit(ctx, new ExitCodeGenerator() { - @Override - public int getExitCode() { - // return the error code - return 0; - } + int exitCode = SpringApplication.exit(ctx, () -> { + // return the error code + return 0; }); System.out.println("Exit Spring Boot"); diff --git a/spring-boot/src/main/java/org/baeldung/common/resources/ExecutorServiceExitCodeGenerator.java b/spring-boot/src/main/java/org/baeldung/common/resources/ExecutorServiceExitCodeGenerator.java index 451abdfc37..be33d64c5d 100644 --- a/spring-boot/src/main/java/org/baeldung/common/resources/ExecutorServiceExitCodeGenerator.java +++ b/spring-boot/src/main/java/org/baeldung/common/resources/ExecutorServiceExitCodeGenerator.java @@ -1,10 +1,10 @@ package org.baeldung.common.resources; +import org.springframework.boot.ExitCodeGenerator; + import java.util.Objects; import java.util.concurrent.ExecutorService; -import org.springframework.boot.ExitCodeGenerator; - public class ExecutorServiceExitCodeGenerator implements ExitCodeGenerator { private ExecutorService executorService; @@ -14,16 +14,15 @@ public class ExecutorServiceExitCodeGenerator implements ExitCodeGenerator { @Override public int getExitCode() { - int returnCode = 0; try { if (!Objects.isNull(executorService)) { executorService.shutdownNow(); - returnCode = 1; + return 1; } - } catch (SecurityException ex) { - returnCode = 0; - } - return returnCode; - } + return 0; + } catch (SecurityException ex) { + return 0; + } + } }