Skip to content

Instantly share code, notes, and snippets.

View benelog's full-sized avatar

Sanghyuk Jung benelog

View GitHub Profile
@benelog
benelog / java-memory-model.md
Last active August 30, 2026 13:57
Java memory model

https://en.wikipedia.org/wiki/Java_memory_model#:~:text=The%20Java%20Memory%20Model%20(JMM,consistent%20and%20reliable%20Java%20applications.

By doing this, it makes it possible to reason about code execution in a multithreaded environment, even in the face of optimizations performed by the dynamic compiler, the processor(s), and the caches.

최적화 기법은 컴파일 타임의 reordering이 될수도 있고, 변수의 저장 공간에 CPU cache가 쓰일수도 있음.. Effective Java에서는 전자만을 오히려 이야기. 'OpenJDK 서버 VM이 실제로 적용하는 끌어올리기(hoisting)라는 최적화 기법이다.'

thread별 working 메모리는 CPU cache를 쓴다?

  • JDK 구현체에서 결과적으로 thread 별 working memory에서 CPU cache를 쓸 수도 있지만, 그것이 명세로서 보장된다는 권위 있는 자료를 찾지는 못함
@benelog
benelog / interface-reference.adoc
Created August 30, 2026 13:22
인터페이스를 통한 참조

인터페이스를 통한 참조

메서드 시그니처와 로컬변수를 ArrayList같은 구현 클래스로 참조하기보다는 java.util.List같은 인터페이스로 참조하는것을 권장한다.

public ArrayList<Track> findMyTracks() {

}
@benelog
benelog / guard.adoc
Created August 30, 2026 13:20
보호절

보호절

예를 들면 아래와 같이 중첩된 if/else 절은

public Alarm evaluate(Issue issue) {
    Alarm alarm = null;
    if (issue.getStatus() == Status.OPEN) {
@benelog
benelog / remove-unnecessaries.adoc
Created August 30, 2026 13:12
불필요한 코드 없애기

불필요한 코드 없애기

의미 없는 초기화 하지 않기

실제로 쓰이지 않은 초기값을 할당하기 위해 생성자 등을 호출하는 경우가 있다. 예를 들면 아래 코드에서 ArrayList의 생성자를 호출했지만, 실제로 그 객체는 않고, 바로 다음줄에서 참조가 해제된다.

List<Issue> issueList = new ArrayList<>();
issueList = issueService.findList(condition);
@benelog
benelog / logging.adoc
Created August 30, 2026 13:07
Java logging

로깅

가장 단순하게는 System.out.println`으로 그런 정보를 남기는 경우가 있다. JDK에서도 `java.util.logging 패키징 아래에서 기본적인 로깅 프레임워크를 제공한다. Java로 웹 어플리케이션을 개발하는 실무에서는 체계적이면서 유연한 방식으로 로그를 관리하기 위해서 오픈소스 로깅 프레임워크들을 대부분 사용한다.

이 단락에서는 로깅 프레임워크 간의 역할과 특징, 핵심적인 사용법, 실무에서 적용할 때에 주의할 점을 설명한다.

@benelog
benelog / auto-boxing.adoc
Created August 30, 2026 13:05
Auto Boxing

Auto boxing 남용하지 않기

Auto boxing-unboxing을 주의해서 사용하지 않으면 Null pointer exception을 유발하거나 불필요한 객체를 생성할 수 있다. 컴파일러가 이를 어떻게 변환하는지 이해를 해야 안전하고 효율적으로 사용할 수 있다.

아래와 같은 소스를 컴파일한후,

int i1 = 1;
Integer i2 = 2;
System.out.println(i1 == i2);
System.out.println(i2 == i1);
@benelog
benelog / exception.adoc
Created August 30, 2026 13:02
Java Exception

예외 처리

예외를 무시하지 않기

아래와 같이 catch절에서 아무 것도 하지 않는 코드는 디버깅을 어렵게 한다.

try {
    process();
@benelog
benelog / vo-vs-dto.adoc
Created August 30, 2026 12:54
VO와 DTO 보강

Effective Java의 Item 52에서는 이런 성격의 클래스를 'Value classes’라고 했다.

Java Persistence with Hibernate 에서는 Value type으로 칭했다.

이런 현상 때문에 VO라는 용어에 불만을 표하고 Valjo라는 새로운 용어를 도입하자는 주장도 있다.

The term "value object" gets confusing in Java circles with various different interpretations. ( http://blog.joda.org/2014/03/valjos-value-java-objects.html 중에서 )

ttp://martinfowler.com/eaaCatalog/domainModel.html[Domain Model] 정도로 칭하는 수도 있다.

@benelog
benelog / git-ignore-secret-sops.md
Last active August 1, 2026 01:19
Git 무시 규칙(.gitignore vs .git/info/exclude)과 비밀 관리 도구(git-secret, SOPS) 정리

Git의 무시 규칙과 비밀 관리 도구 정리

.gitignore와 .git/info/exclude의 차이에서 출발해, 저장소에 비밀을 다루는 도구인 git-secret·SOPS와 비밀 유출 스캐너 gitleaks까지 정리한 노트.

1. .gitignore vs .git/info/exclude

둘 다 같은 문법으로 무시할 파일 패턴을 적지만, 공유 여부가 다르다.

.gitignore .git/info/exclude
@benelog
benelog / helix-go-test-keybindings.md
Last active July 30, 2026 22:12
Helix에서 Go 테스트 실행하는 키바인딩 설정

Helix에서 Go 테스트 실행하기

Helix 에디터에는 내장 터미널이 없지만, :sh(:run-shell-command) 명령과 키바인딩을 조합하면 에디터 안에서 바로 Go 테스트를 실행하고 결과를 팝업으로 확인할 수 있다.

Helix 25.07 기준으로 확인했다.

설정

~/.config/helix/config.toml: