Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Go언어
- 동적프로그래밍
- 파이썬
- boj
- OOM
- programmers
- codewars
- leetcode
- zookeeper
- 튜토리얼
- 자바
- 스칼라
- 프로그래머스
- 알고리즘
- Linux
- dynamic programming
- DP
- 리눅스
- scala
- golang
- go
- 주키퍼
- redis
- 코드워
- gradle
- Java
- docker
- Python
- HBase
- 문제풀이
Archives
- Today
- Total
목록thread (1)
파이문
멀티쓰레드에서 싱글톤 클래스 사용 예제
싱글톤 클래스 예제는 보통 아래 처럼 작성되곤 한다. public static class Singleton { private static Singleton instance; private Singleton() { } public static Singleton getInstance() { if (instance == null) { instance = new Singleton(); } return instance; } } 이렇게 작성하면 단일 쓰레드에서는 문제가 없지만, 멀티 쓰레드(multithread) 에서는 instance 를 가져올 때 (동시 접근하여 instance 를 null 로 판단한 경우) 문제가 생길 수 있다. 가장 쉬운 방법은 getInstance 함수에 synchronized 키워드를 넣..
Java
2020. 10. 8. 21:03