From 2e58dd0ce5a753278110d705fde5a871922c7f54 Mon Sep 17 00:00:00 2001 From: KyungMin Lee Date: Thu, 29 Aug 2024 11:29:14 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Hot Fix: 의존성 관련 부분을 해결했습니다. --- .../java/info/logbat/domain/log/queue/LogQueue.java | 4 ---- .../logbat/domain/log/queue/ReentrantLogQueue.java | 3 ++- .../logbat/domain/log/queue/SingleLinkLogQueue.java | 7 ++----- .../domain/log/repository/AsyncMultiProcessor.java | 12 +++++++----- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/logbat/src/main/java/info/logbat/domain/log/queue/LogQueue.java b/logbat/src/main/java/info/logbat/domain/log/queue/LogQueue.java index 19415d6..4253bc4 100644 --- a/logbat/src/main/java/info/logbat/domain/log/queue/LogQueue.java +++ b/logbat/src/main/java/info/logbat/domain/log/queue/LogQueue.java @@ -7,8 +7,6 @@ import java.util.List; import java.util.concurrent.locks.LockSupport; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Primary; -import org.springframework.stereotype.Component; /** * 로깅 데이터 전달 목적의 Thread-Safe Queue 구현체로, 생산과 소비 작업을 모두 지원합니다. 이 클래스는 단일 스레드 환경에서 작동하도록 설계되었으며, 효율적인 @@ -21,8 +19,6 @@ * * @param 이 큐에 저장되는 요소의 타입 */ -@Primary -@Component public class LogQueue implements EventProducer, EventConsumer { // T 타입의 요소를 저장하는 list diff --git a/logbat/src/main/java/info/logbat/domain/log/queue/ReentrantLogQueue.java b/logbat/src/main/java/info/logbat/domain/log/queue/ReentrantLogQueue.java index d63a7bf..97f3488 100644 --- a/logbat/src/main/java/info/logbat/domain/log/queue/ReentrantLogQueue.java +++ b/logbat/src/main/java/info/logbat/domain/log/queue/ReentrantLogQueue.java @@ -9,9 +9,10 @@ import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.ReentrantLock; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; -//@Primary +@Scope("prototype") @Component public class ReentrantLogQueue implements EventProducer, EventConsumer { diff --git a/logbat/src/main/java/info/logbat/domain/log/queue/SingleLinkLogQueue.java b/logbat/src/main/java/info/logbat/domain/log/queue/SingleLinkLogQueue.java index 058be56..3bcafad 100644 --- a/logbat/src/main/java/info/logbat/domain/log/queue/SingleLinkLogQueue.java +++ b/logbat/src/main/java/info/logbat/domain/log/queue/SingleLinkLogQueue.java @@ -2,13 +2,10 @@ import info.logbat.common.event.EventConsumer; import info.logbat.common.event.EventProducer; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - import java.util.ArrayList; import java.util.List; +import org.springframework.beans.factory.annotation.Value; -@Component public class SingleLinkLogQueue implements EventProducer, EventConsumer { private final SingleLinkedList queue = new SingleLinkedList<>(); @@ -16,7 +13,7 @@ public class SingleLinkLogQueue implements EventProducer, EventConsumer private final int bulkSize; public SingleLinkLogQueue(@Value("${jdbc.async.timeout}") Long timeout, - @Value("${jdbc.async.bulk-size}") Integer bulkSize) { + @Value("${jdbc.async.bulk-size}") Integer bulkSize) { this.timeout = timeout; this.bulkSize = bulkSize; } diff --git a/logbat/src/main/java/info/logbat/domain/log/repository/AsyncMultiProcessor.java b/logbat/src/main/java/info/logbat/domain/log/repository/AsyncMultiProcessor.java index 6ab3adc..4c063d1 100644 --- a/logbat/src/main/java/info/logbat/domain/log/repository/AsyncMultiProcessor.java +++ b/logbat/src/main/java/info/logbat/domain/log/repository/AsyncMultiProcessor.java @@ -12,6 +12,7 @@ import java.util.function.Consumer; import javax.sql.DataSource; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Primary; import org.springframework.jdbc.core.JdbcTemplate; @@ -26,13 +27,16 @@ public class AsyncMultiProcessor implements EventProducer { private final List flatterExecutors; private Consumer> saveFunction; private final int queueCount; + private final ObjectProvider> objectProvider; public AsyncMultiProcessor(@Value("${queue.count:3}") int queueCount, @Value("${jdbc.async.timeout:5000}") Long timeout, - @Value("${jdbc.async.bulk-size:3000}") Integer bulkSize, JdbcTemplate jdbcTemplate) { + @Value("${jdbc.async.bulk-size:3000}") Integer bulkSize, JdbcTemplate jdbcTemplate, + ObjectProvider> objectProvider) { this.queueCount = queueCount; this.queues = new ArrayList<>(queueCount); this.flatterExecutors = new ArrayList<>(queueCount); + this.objectProvider = objectProvider; int poolSize = getPoolSize(jdbcTemplate); setup(queueCount, timeout, bulkSize, poolSize); } @@ -51,14 +55,12 @@ public void produce(List data) { } private void setup(int queueCount, Long timeout, Integer bulkSize, int poolSize) { - ExecutorService followerExecutor = Executors.newFixedThreadPool(poolSize); - ReentrantLogQueue queue = new ReentrantLogQueue<>(timeout, bulkSize); - + ReentrantLogQueue queue = objectProvider.getObject(timeout, bulkSize); for (int i = 0; i < queueCount; i++) { queues.add(queue); flatterExecutors.add(Executors.newSingleThreadExecutor()); } - CompletableFuture.runAsync(() -> leaderTask(queue, followerExecutor)); + CompletableFuture.runAsync(() -> leaderTask(queue, Executors.newFixedThreadPool(poolSize))); } private void leaderTask(ReentrantLogQueue queue, ExecutorService follower) {