Spring
-
토비의 봄 TV - 자바의 비동기 기술 (4) 1/2Spring/Webflux 2022. 6. 17. 00:11
ExcutorService 쉽게 비동기로 작업을 실행할 수 있도록 도와주는 JDK(1.5부터)에서 제공하는 interface 이다. 일반적으로 ExecutorService는 작업 할당을 위한 스레드 풀과 API를 제공한다. @Slf4j public class ExcutorServiceApp { public static void main(String[] args) { ExecutorService es = Executors.newCachedThreadPool(); es.execute(() -> { try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } log.info("Async"); System.out.print..
-
토비의 봄 TV - Reactive Streams Scheduler (3)Spring/Webflux 2022. 6. 14. 23:50
해당 강좌에서는 publisher, subscriber 의 동작 코드를 reactive streams 에서 제공하는 scheduler 를 이용하여 서로 다른 스레드에서 동작하도록 해보자. 스케줄러 (Scheduler) 메인 쓰레드가 언제 일어날줄 모르는 이벤트를 blocking 방식으로 무한정 기다리는건 비효율적 이다. 비동기로 효율적으로 처리 될 수 있도록 다른 쓰레드를 이용하거나 생성하는데, 이를 스케줄러라 부른다. 스케줄러 (Scheduler) 종류 publishOn publisher(데이터 생성)는 빠르나 subscriber(데이터 사용)쪽의 작업이 느린 경우 subscriber를 별도의 쓰레드로 분리 e.g) 데이터 가공/저장 작업이 느린경우 사용 subscribeOn publisher가 느리고..
-
토비의 봄 TV - Reactive Streams Operators (2)Spring/Webflux 2022. 6. 7. 14:42
Observable 형태를 발전시킨 Publisher 와 Subscriber 를 만드는 방식을 이전 시간에 살펴보았다. 이번엔 이를 조금 더 발전 시켜서 Operator 를 추가하는 방법과 동작방식을 살펴보고 실제 Reactive Strems 의 구현체인 Reactor 까지 사용해보자. 복습 ReactiveStreams 는 아래 기능들을 제공한다. Publisher Subscriber Subscription Processor Publisher 가 가장 중요한데, 데이터스트림을 계속해서 만들어내는 Provider 역할을 한다. 아래 코드를 살펴보자. import org.reactivestreams.Publisher; import org.reactivestreams.Subscriber; import org...
-
토비의 봄 TV - Reactive Streams (1)Spring/Webflux 2022. 6. 4. 12:38
Reactive Programming 데이터가 변경될 때 마다 이벤트를 발생시켜서 데이터를 계속적으로 전달하는 Push 방식에 중점을 둔 프로그램 패러다임 Push 방식 (비동기 방식) 비동기 방식으로 데이터의 변화가 발생했을 때 변경이 발생한 곳에서 데이터를 보내주는 방식을 말한다. Iterable 과 Observable Iterable 데이터 순회를 가능하게 해주는 인터페이스이다. java 에서 제공되고 있는 Iterator 패턴의 인터페이스 list 와 같은 collection 들은 Iterable 을 상속 받고 있다. Iterable 를 상속받은 하위 객체들은 for-each loop 를 사용할 수 있다. Iterable 인터페이스 안에는 iterator 라는 메서드가 존재한다. Iterator ..
-
JDBC Statement와 PreparedStatementSpring 2021. 7. 5. 11:27
→ 이 둘의 가장 큰 차이는 캐시사용 여부의 차이이다. 쿼리문을 실행하게 될 때 [문장분석 → 컴파일 → 실행단계] 의 과정을 실행하게 되는데 Statement 의 경우 쿼리가 매번 실행될 때 이러한 과정이 일어나는 반면, PreparedStatement 의 경우 처음만 위 과정을 거친 후에 캐싱된 실행계획을 재사용하므로 DB 부하를 줄일 수 있다. PreparedStatement 미리 컴파일 한 후 파라미터 값만 동적쿼리로 재사용할 때 주로 사용된다. 개발자 의도에 작성된 쿼리문이 캐싱되어 있으므로 SQL Injection 과 같이 임의적인 SQL문을 주입하여 실행되게 하는 보안상의 이슈도 막을 수 있다. Statemetn 단 한번의 조회나 create, alter, drop 같은 작업을 할 시에는 S..