분류 전체보기
-
이펙티브 자바 - equals & hashcode개발 나누고 더하기/자바, 스프링 2023. 6. 28. 22:29
equals와 hashcode는 루트 클래스인 Object에서 제공하는 오퍼레이션이고 모든 클래스들은 이 두 메서드를 재정의하지 않는 이상 Object에 정의되어 있는대로 쓰게 된다. 실무에서는 주로 식별자로 두 객체가 동일한지 비교하고 가끔 값 객체 비교에 써서 equals를 직접 구현했던 일이 적었다. HashMap, HashSet에 key로 enum이나 Integer, String같은 기본 랩퍼 클래스를 써서 hashcode는 볼일이 거의 없었지만 이 기회에 다시 한번 짚어보는것도 좋을 것 같다. equals는 일반 규약을 지켜 재정의하라 equals 메서드는 재정의하기 쉬워 보이지만 곳곳에 함정이 도사리고 있어서 자칫하면 끔찍한 결과를 초래한다. 문제를 회피하는 가장 쉬운 길은 아예 재정의하지 않..
-
Set에 대하여 2 : 주요 구현체개발 나누고 더하기/자바, 스프링 2023. 6. 25. 22:59
이전 글(https://baby-care-dev.tistory.com/47)에서는 Set의 구조와 메서드에 대해 알아봤다. 메서드 동작은 알았지만 구현체별로 어떻게 내부가 처리되는지도 궁금하다. 예를 들면 TreeSet이나 LinkedHashSet은 어떻게 순서를 보장하는지 등 말이다. 이번에는 구현체별 특징과 공통점/차이점에 대해 알아보자. Set 상속 구조 위 그림에 나온 구현체들 보다 많은 구현 클래스들이 존재하는데, 일단 이정도만 알아도 될 듯 싶다. 모두 공통적으로 AbstractSet이라는 추상 클래스를 상속받고 있다. 이 AbstractSet에서 추상화된 공통점을 파악할 수 있으니 먼저 알아보자. AbstractSet 제공하는 메서드는 equals, hashCode, removeAll이다. ..
-
Set에 대하여 1 : 구조와 주요 메서드개발 나누고 더하기/자바, 스프링 2023. 6. 23. 23:39
Set은 내가 좋아하는 자료구조이다. 중복없이 원소들을 담아놓은 집합체이고, 용도도 중복 검사로 주로 쓰이는 아주 군더더기 없는 구성이라 뭔가 깔끔하다. 그런데 이번에 Set을 org.springframework.cache.annotation.Cacheable에 사용하다 버그를 만들어냈다. 왜 그렇게 생각했는지 모르겠는데 레디스가 Set을 지원하니 key에 사용되는 타입도 Set을 지원할 줄 알았다. 하지만 Key는 정직하게 스트링 값으로만 비교를 했고, 의도치 않게 여러가지 버전의 캐시를 만들어 내고 말았다. 대략 아래 코드와 같았다. List로 할까 고민했었는데, 좀 안일했었다. 로컬과 개발(인스턴스 2대) 환경에서 테스트해도 문제가 없었지만 운영환경에서 몇십대(정확한 대수는 공개하기 민감하므로^^)..
-
이펙티브 자바 - 정적 팩터리 메서드책책책 책을 읽읍시다/프로그래밍 2023. 6. 22. 23:46
저자 : 조슈아 블로크(Joshua Bloch) 옮긴이 : 이복연 들어가며 2015년 11번가 인턴 때 중도포기, 2017년쯤 이랜드에서도 중도포기... 영화든 책이든 재미없더라도 끝까지 가고 보는 성격인데 왠지 이 책만큼은 재미있음에도 완독을 못했다. 이번에는 꼭 성공하길 바라는 마음에서 완독 전에 먼저 블로그 글을 올리는 배수진을 쳤다. 그땐 몰랐는데 지금은 당연하게 실무에서 적용하고 있는 패턴이 여기에 소개되어있어 신기했다. 그만큼 내용적으로 훌륭해서 다른 곳에서 재생산되어 나에게 왔다는 의미로 받아들여졌다. 알고 있는 패턴들을 다시 찬찬히 보며 생각할게 많아져서 이번에는 소단원 단위로 정리하겠다. 정적 팩터리 메서드 너무나도 유명하므로 장단점만 간단하게 짚어본다. 장점 첫째, 이름을 가질 수 있다..
-
함께 자라기 : 애자일로 가는 길책책책 책을 읽읍시다/프로그래밍 2023. 6. 19. 22:05
저자 : 김창준 들어가며 성장에 관심 많은 개발자라면(이렇게 말하는 이유는 성장에 관심 없는 개발자도 많기 때문이다) 꼭 읽어볼만한 책이다. 현재까지의 자기 성장을 돌아보고 앞으로 동료들과 어떻게 더 성장할 지에 대해 도움받을 수 있기 때문이다. 보는 내내 전 직장인 이랜드에서 후배들 온보딩할 때 참 안좋은 방식으로 했다는 미안함이 들었고, 그에 맞게 나도 실력적으로건 인격적으로건 성장을 잘 못했다는 후회가 들었다. 한 가지 아쉬운 건 중간중간 논리를 뒷받침할 저자 본인의 재미있는 블로그 글이 주석으로 실렸는데, 2023년 6월 16일 이후로 egloos가 서비스를 종료함에 따라 더 볼 수 없게 된다는 점이다. 김창준님 블로그는 찾아봤는데 egloos 외에는 안나온다. 아무튼 이제 8년차에 접어든 나에게..
-
leetcode easy - Two Sum개발 나누고 더하기/코딩 테스트 2023. 6. 14. 22:33
문제 Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. Integer 타입의 배열이 있고, 이중 2개를 뽑아 더해서 target과 같은 값이 나오는 인덱스를 반환해야 한다. 예제 1 Input: nums = [2,7,11,15], target = 9 Output: [0,1] Ex..
-
카프카 핵심 가이드 5 : 멱등성책책책 책을 읽읍시다/프로그래밍 2023. 6. 12. 23:07
8. '정확히 한 번' 의미 구조 멱등적 프로듀서 멱등성 의미 구조가 아닌 '최소 한 번' 의미 구조를 가지도록 프로듀서를 설정한다면, 프로듀서가 메세지 전송을 재시도함으로써 메세지가 최소 한 번 이상 도착할 수 있는 불확실성이 존재하게 된다. 이렇게 재시도는 메세지 중복으 발생시킬 수 있다. 가장 고전적인 경우리면, 이런 경우가 있겠다. 파티션 리더가 프로듀서로부터 레코드를 받아서 팔로워들에게 성공적으로 복제한다. 프로듀서에게 응답을 보내기 전, 파티션 리더가 있는 브로커에 크래시가 발생한다. 프로듀서 입장에서는 응답을 받지 못한 채 타임아웃이 발생하고, 메세지를 재전송한다. 재전송된 메세지가 새 리더에 도착한다. 하지만 이 메세지는 이미 저장되어 있다(결과적으로, 중복이 발생한다). 어떤 애플리케..
-
카프카 핵심 가이드 4 : 내부 메커니즘책책책 책을 읽읍시다/프로그래밍 2023. 6. 11. 15:47
6. 내부 메커니즘복제 복제는 카프카 아키텍처의 핵심이다. 실제로 카프카는 '분산되고, 분할되고, 복제된 커밋 로그 서비스'로 표현되기도 한다. 복제가 중요한 이유는 개별적인 노드에 필연적으로 장애가 발생할 수밖에 없는 상황에서 카프카가 신뢰성과 지속성을 보장하는 방식이기 때문이다. 카프카에 저장되는 데이터는 토픽을 단위로 해서 조직화한다. 각 토픽은 1개 이상의 파티션으로 분할되며, 각 파티션으 다시 다수의 레플리카를 가질 수 있다. 각각의 레플리카는 브로커에 저장되는데, 대개 하나의 브로커는 (서로 다른 토픽과 파티션에 속하는) 수백 개에서 심지어 수천 개의 레플리카를 저장한다. 레플리카에는 두 종류가 있다.리더 레플리카 : 각 파티션에는 리더 역할을 하는 레플리카가 하나씩 있다. 일관성을 보장하기 ..