parent
df42f243f2
commit
0e95588c54
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue