Skip to content

Commit

Permalink
feat: 멀티스레드 종료 시 자원 반납 대기 시간 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Arachneee committed Dec 11, 2024
1 parent 6bf492b commit eb1b639
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions server/src/main/java/haengdong/event/config/S3Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand All @@ -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();
}
}
}

0 comments on commit eb1b639

Please sign in to comment.