Programming/jsp

thread-safe singleton

구차니 2014. 4. 25. 17:13
로그인 로직을 싱글톤으로 사용시 
과연 thread-safe할까? 라는 생각에 검색해보니 똭!

결론은 일반 싱글톤은 당연히 thread-safe하지 않으니
synchronized 등으로 동기화를 하거나(퍼포먼스 저하..)

ThreadLocal로 쓰레드별 로컬 변수로 생성하거나 등으로 회피를 하는 것으로 보인다.
[링크 : http://docs.oracle.com/javase/7/docs/api/java/lang/ThreadLocal.html]



[링크 : http://www.javaservice.net/~java/bbs/read.cgi?m=devtip&b=javatip&c=r_p&n=1028393658]
  [링크 : http://www.cs.umd.edu/~pugh/java/memoryModel/DCL-performance.html] << 원문
[링크 : http://levin01.tistory.com/307] << 부분 번역
[링크 : http://en.wikipedia.org/wiki/Singleton_pattern#Example