전체 글
-
BigDecimal ❓☕️ java 2023. 3. 7. 11:05
❓BigDecimal 🧐 사용하는 이유 @Test void test() { double a = 100.0000000005; double b = 10.0000000004; assertThat(a - b).isEqualTo(90.0000000001); } 결과 expected: 90.0000000001 but was: 90.00000000009999 📖 왜 실패를 할까? 자바는 IEEE 754 부동 소수점 방식을 사용한다. 따라서, 정확한 실수를 저장하지 않고 최대한 완벽에 가깝기 바라는 근사치 값을 저장한다. 금융권 같은 사소한 값 차이가 중요한 곳에서 double 타입을 사용하게 되면 문제가 될 수 있다 이런 문제점을 해결하기 위해 부동 소수점 방식이 아닌 정수를 이용해 실수를 표현하는 java.math..
-
[Java] String / StringBuffer / StringBuilde☕️ java 2023. 3. 3. 21:16
Java에서 문자열을 다루는 대표적인 클래스로는 String, StringBuffer, StringBuilder가 있다. 연산 횟수가 많아지거나 멀티스레드, Race condition 등의 상황이 발생한다면 각 클래스의 특징을 이해하고 상황에 맞는 클래스를 사용하는 것이 중요하다!! 📌 String vs StringBuffer / StringBuilder 💡 String 과 StringBuffer / StringBuilder 클래스의 가장 큰 차이점 String은 불변 속성이라는 것!! String은 불변 ❓ String str = "hello"; str = str + " world!"; 위 코드에서 str이 가리키는 곳에 “hello world!” 가 저장되어 있다고 생각할 수 있다. 하지만, 기존 “..
-
[Java] Static 과 Final☕️ java 2023. 3. 3. 19:27
📌 Static Java에서 Static 키워드를 사용한다는 것은 메모리에 한번 할당되어 프로그램이 종료될 때 해제되는 것을 의미 GC가 관리 ❌ 일반적으로 만든 Class는 Static 영역에 생성 new 연산을 통해 생성한 객체는 Heap 영역에 생성 📖 GC Heap 영역의 메모리는 GC를 통해 수시로 관리받는다. 하지만 Static 키워드를 통해 Static 영역에 할당된 메모리는 객체가 공유하는 메모리라는 장점이 있지만 GC의 관리 영역 밖이다. Static을 자주 사용하면 프로그램이 종료될 때까지 메모리가 할당된 상태로 존재한다. 자주 사용시 문제가 될 수 있다. 📌 Static 변수 - Static 변수는 클래스 변수이다. - 객체를 생성하지 않고도 Static 자원에 접근이 가능하다. 💡 ..
-
Reflection API ?☕️ java 2023. 2. 9. 19:43
📌 Reflection API 💡 구체적인 클래스 타입을 알지 못해도 그 클래스의 정보(메서드, 타입, 변수 등등)에 접근할 수 있게 해주는 자바 API 📌 Reflection API 기능 Person.java public class Person { private String name; protected String address; public int age; } 필드 접근 Class 클래스의 getFields() 메서드 public으로 선언된 필드만 조회가 가능 Class 클래스의 getDeclaredFields() 메서드 Test @Test void get_field() { Object person = new Person(); Field[] getFields = person.getClass().get..
-
커스텀 validation 만들기☕️ java 2023. 1. 28. 17:46
스프링 프레임워크가 기본적으로 제공하는 Validator Annotation으로 충분하지 않을 수 있다. 필요에 따라 직접 Validator를 구현해야 하는 경우가 생길 수 있다. ❗Annotation Custom Constraint Annotation을 만들 때에는 message groups payload 위 3개는 꼭 정의를 해주어야 한다. @Constraint(validatedBy = PasswordValidator.class) @Target({METHOD, FIELD, ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface PasswordValidation { String message() default "Password i..
-
ThreadLocal🌱 spring 2023. 1. 18. 19:08
📌 ThreadLocal 💡 한 스레드에 의해서만 일고 쓰일 수 있는 변수 서로 다른 두 스레드가 하나의 변수에 접근했을 때, 해당 변수는 공유자원으로 동시성 문제가 발생할 가능성이 있다. ThreadLocal은 오직 한 스레드에 의해 읽고/쓰일 수 있는 변수를 생성한다. 두 스레드가 같은 코드를 실행하고 이 코드가 하나의 threadLocal 변수를 참조하더라도 서로의 threadLocal 변수를 볼 수 없다. 예시 ThreadA가 ThreadLocal 변수에 접근하여 1이라는 값을 저장. 동시에 ThreadB가 ThreadLocal 변수에 접근해 2라는 값을 저장 1이라는 값을 2가 덮는 것이 아니다 ❌ 각 스레드별 전용 저장소에 각각의 값이 저장된다. ⇒ 멀티 스레드 환경에서 공유 자원의 동시성 문..
-
4장. 카프카 상세 개념 - 토픽과 파티션📕 book/아파치 카프카 2023. 1. 17. 13:52
4장. 카프카 상세 개념 - 토픽과 파티션 ⭐ 토픽과 파티션 토픽은 카프카의 시작과 끝이다. 토픽을 만들면서 카프카를 사용하기 시작한다. 토픽에 대해 잘 이해하고 설정을 잘하는 것이 카프카를 통한 데이터 활용도를 높이는 것이다!! 📌 적정 파티션 개수 토픽의 파티션 개수는 카프카 성능과 관련있다. 토픽 생성 시 파티션 개수 고려사항 데이터 처리량 메시지 키 사용 여부 브로커, 컨슈머 영향도 데이터 처리량 파티션은 카프카 병렬처리의 핵심이다. 파티션의 개수가 많아질 수록 매핑되는 컨슈머 개수가 증가하기 때문 따라서, 파티션 개수를 정할 때 토픽에 필요한 데이터 처리량을 측정해 정하는 것이 중요 파티션 개수만큼 컨슈머 스레드를 운영하면 토픽의 병렬처리를 극대화 할 수 있다. 👀 컨슈머 전체 데이터 처리량이 ..
-
11장 - CQRS📕 book/도메인 주도 개발 시작하기 2023. 1. 16. 11:05
📌 단일 모델의 장점 조회를 하는 과정에 여러 애그리거트의 데이터가 필요한 경우 조회 속도를 빠르게 하기 위해서 구현 방법을 고민해야 한다. 식별자를 이용해 애그리거트를 참조하는 방식 즉시 로딩방식과 같은 JPA의 쿼리 관련 최적화 기능을 사용할 수 없다. 애그리거트 간 연관을 직접 참조하는 방식 조회 화면의 특성에 따라 즉시 로딩, 지연 로딩으로 처리해야 한다. 이런 고민이 발생하는 이유 상태를 변경할 때와 조회할 때 단일 도메인 모델을 사용하기 때문 ORM 기법은 도메인 상태 변경 기능을 구현하는데 적합하다 하지만, 여러 애그리거트에서 데이터를 가져오는 기능을 구현하기에는 고려할 것이 많아 복잡하게 만든다. 복잡도를 낮추기 위해 상태 변경을 위한 모델과 조회를 위한 모델을 분리하는 것이 좋다. ⭐ C..