JVM

JVM/Spring

[Toby Spring Reactive Programming] 비동기 RestTemplate과 비동기 MVC/Serlvet (5)

서론 https://www.youtube.com/watch?v=ExUfZkh7Puk 토비님의 유튜브 강의 내용을 정리한 글 입니다. 본론 @RestController public static class MyController { AsyncRestTemplate rt = new AsyncRestTemplate(); @GetMapping("/rest") public String rest(int idx) { return rt.getForEntity("http://localhost:8081/service?req={req}", String.class, "hello" + idx); } } AsyncRestTemplate을 사용하면, 톰캣 스레드 1개로 처리가 가능하다. 하지만, 백그라운드 스레드가 생성되어 처리하기..

JVM/Spring

[Toby Spring Reactive Programming] 자바, 스프링의 비동기 (4)

서론 https://www.youtube.com/watch?v=aSTuQiPB4Ns 토비님의 유튜브 강의 내용을 정리한 글 입니다. 본론 스프링 컨트롤러 리턴타입에 따른 동작방식 #1 Object @GetMapping("/async") public String async() throws InterruptedException { log.info("async"); Thread.sleep(2000); return "hello"; } 기본 tomcat thread pool 수인 200개 까지만 동시처리가 가능하다. [링크] https://tomcat.apache.org/tomcat-8.5-doc/config/executor.html #2 Callable @GetMapping("/callable") public ..

JVM/Spring

[Toby Spring Reactive Programming] Schedulers (3)

서론 https://www.youtube.com/watch?v=Wlqu1xvZCak 토비님의 유튜브 강의를 보고 정리한 내용입니다. 본론 https://kdhyo98.tistory.com/136 이전 코드까지는 모두 main스레드에서 동작했다. 하지만, IO나 큰 계산같은 작업들이 있다면 main스레드가 끝날 때까지 멈추게 되는데, 모바일 어플로 생각하면 버튼을 누를 때 작업을 완료될 때까지 멈추게 된다. 사용자가 작업 처리를 기다리지 않고 다른 이벤트를 받을 수 있도록 백그라운드에서 동작시켜야 하는데, 이걸 main이 아닌 다른스레드에 작업을 넘겨 처리할 수 있다. Ractive Streams 구현 사용자가 다 확인할 필요가 없는 경우에는 백그라운드에서 동작을 시켜 main은 다른 이벤트를 받게 할 수..

JVM/Spring

[Toby Spring Reactive Programming] Operators (2)

서론 https://www.youtube.com/watch?v=DChIxy9g19o 토비님 유튜브 강의를 보고 정리한 내용입니다. 본론 Operator https://kdhyo98.tistory.com/135 첫 번째 강의에서 Publisher, Subscriber를 하나씩 사용해서 리액티브 스트림즈를 간단하게 알아봤다. Operator는 기존 Publisher -> Subscriber에서 중간에 연산자를 두어 결과를 변경하거나 10개를 1개만 최종으로 보내거나 하는 녀석을 말한다. Publisher (DataA) -> (DataA) Operator (DataB) -> (DataB) Subscriber 느낌이다. Java 8의 스트림을 생각하면 이해하기 쉽다. 스트림의 map, reduce, filter..

JVM/Kotlin

[Coroutines] Dispatchers 알아보기

예제 fun main(): Unit = runBlocking { launch { // #1 println("main runBlocking : I'm working in thread ${Thread.currentThread().name}") } launch(Dispatchers.Unconfined) { // #2 println("Unconfined : I'm working in thread ${Thread.currentThread().name}") } launch(Dispatchers.Default) { // #3 println("Default : I'm working in thread ${Thread.currentThread().name}") } launch(newSingleThreadContext("M..

JVM/Spring

[Toby Spring Reactive Programming] Reactive Streams 시작 (1)

서론 https://youtu.be/8fenTR3KOJo 토비의 스프링에 있는 토비님의 라이브 유튜브 강의를 보고 정리한 내용입니다. 본론 Iterable vs Observable Iterable public static void main(String[] args) { Iterable iter = () -> new Iterator() { int i = 0; final static int MAX = 10; public boolean hasNext() { return i < MAX; } public Integer next() { return ++i; } }; iter.forEach(System.out::println); } Iterable 인터페이스를 구현하면, for-each를 사용할 수 있다. 주로, C..

JVM/JPA

[Hibernate] 설정 옵션 목록

spring: jpa: properties: hibernate: query: plan_cache_max_size: 1 plan_parameter_metadata_max_size: 1 주로 위와 같이 yaml, properties 를 사용해서 하이버네이트 옵션을 주곤 한다. 자주 사용하는 옵션 외에는 어떤 옵션이 있는지 헷갈릴 때가 있고, 혹은 코드로 직접 옵션을 줄 때 옵션 별로 상수로 직접 구현할 필요 없이 이미 구현된 상수를 발견해서 기록한다. 아래 AvailableSettings는 hibernate-core에 있는 하이버네이트 옵션을 상수로 표현한 인터페이스다. hibernate-envers 또한 상수로 정의되어 있다. 클래스명 - EnversSettings 수동으로 코드에서 옵션을 변경할 때 경로..

JVM/Java

[java] BigDecimal의 equals 와 compareTo with kotlin

😲 서론 BigDecimal 을 통해 연산자를 통해 값을 비교하다가 조심해야될 것을 발견했다. 🫡 본론 결과의 값이 1인지를 확인하려고 했는데, 내 생각과 다르게 false가 나왔다. fun main() { val result = BigDecimal("1.00") println(result == BigDecimal.ONE) // false } equals의 java doc 확인해보니 아래와 같은 설명이 적혀있었다. equals Javadoc Compares this BigDecimal with the specified Object for equality. Unlike compareTo, this method considers two BigDecimal objects equal only if they a..

Hyo Kim
'JVM' 카테고리의 글 목록