Skip to content

Commit 0e95588

Browse files
authored
Refactor (eugenp#3923)
* NatsClient refactor * Use lambda
1 parent df42f24 commit 0e95588

2 files changed

Lines changed: 9 additions & 13 deletions

File tree

‎spring-boot/src/main/java/com/baeldung/shutdown/Application.java‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,9 @@ private static void exitApplication() {
3434

3535
ConfigurableApplicationContext ctx = new SpringApplicationBuilder(Application.class).web(false).run();
3636

37-
int exitCode = SpringApplication.exit(ctx, new ExitCodeGenerator() {
38-
@Override
39-
public int getExitCode() {
40-
// return the error code
41-
return 0;
42-
}
37+
int exitCode = SpringApplication.exit(ctx, () -> {
38+
// return the error code
39+
return 0;
4340
});
4441

4542
System.out.println("Exit Spring Boot");
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package org.baeldung.common.resources;
22

3+
import org.springframework.boot.ExitCodeGenerator;
4+
35
import java.util.Objects;
46
import java.util.concurrent.ExecutorService;
57

6-
import org.springframework.boot.ExitCodeGenerator;
7-
88
public class ExecutorServiceExitCodeGenerator implements ExitCodeGenerator {
99

1010
private ExecutorService executorService;
@@ -14,16 +14,15 @@ public ExecutorServiceExitCodeGenerator(ExecutorService executorService) {
1414

1515
@Override
1616
public int getExitCode() {
17-
int returnCode = 0;
1817
try {
1918
if (!Objects.isNull(executorService)) {
2019
executorService.shutdownNow();
21-
returnCode = 1;
20+
return 1;
2221
}
22+
23+
return 0;
2324
} catch (SecurityException ex) {
24-
returnCode = 0;
25+
return 0;
2526
}
26-
return returnCode;
2727
}
28-
2928
}

0 commit comments

Comments
 (0)