diff --git a/server/src/main/java/haengdong/event/config/S3Config.java b/server/src/main/java/haengdong/event/config/S3Config.java index dee5499b..2a5bd91e 100644 --- a/server/src/main/java/haengdong/event/config/S3Config.java +++ b/server/src/main/java/haengdong/event/config/S3Config.java @@ -3,6 +3,7 @@ import jakarta.annotation.PreDestroy; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import software.amazon.awssdk.regions.Region; @@ -12,6 +13,7 @@ public class S3Config { private static final int THREAD_POOL_SIZE = 10; + private static final int LIFE_CYCLE_SHUTDOWN_TIME_SEC = 10; private final ExecutorService executorService = Executors.newFixedThreadPool(THREAD_POOL_SIZE); @@ -30,5 +32,13 @@ public ExecutorService executorService() { @PreDestroy public void shutdown() { executorService.shutdown(); + try { + if (!executorService.awaitTermination(LIFE_CYCLE_SHUTDOWN_TIME_SEC, TimeUnit.SECONDS)) { + executorService.shutdownNow(); + } + } catch (InterruptedException e) { + executorService.shutdownNow(); + Thread.currentThread().interrupt(); + } } }