- Korea times
- 끌리면 오라...BGM 광고음악 라이브러리
- KartOO visual meta search engi…
- E-Book
- Channel9
- MSDN
- 여리의 작업실
- 유경상의 .NET 블로그
- window 쪼물딱 거리기
- 블루 홈(소현이 누님)
- IT 관련 전반 내용(정환이네)
- 비너스의 정보 공유(유틸리티들)
- 형기의 자료공간(디지털ERA에서 콘텐츠ERA로)
- EzineArticles (여러 분야의 글들이 올라옴)
- Relationship을 보여주는 라이브러리
- OpenRCE
- 젠틀의 블로그(무선 통신의 모든것)
- 헐랭이와 IT보안
- 워니. 추억ㅇㅔ ㅂㅣ추ㅇㅓ.
- Computer Forensics
- 토익 광장(YBM)
- Korea Times 이용하기
- Larkware Software
- TCP/UDP
- Black Hat
- DEF CON
- Slashdot
- ReallyUsefulEbooks.com Update
- 실리콘밸리 뉴스
- Application Development Trends
- Visual Studio Hacks
- MIT OCW
- Redmond Developer News
- SecurityFocus
- Microsoft Window Hacking Porta…
- Darknet - Don't Learn to Hack …
- Windows Tips, Tricks and Hacks
- Hack In the Box
- (IN)SECURE Magazine
- SuperSite Windows Vista
- Government Security
- Life is Still Talking (Good)
- PHRACK
- Found+Read(resource for startu…
- Jonathan Boutelle
- Venture Hacks
- 스마트플레이스
- All about Intellipedia
- Undocumented Windows 2000 Secr…
- HexBlog (Decompiler)
- TED (Ideas worth spreading)
- Crash Dump Analysis and Debugg…
- Rootkit
- DDK Developers(MS)
- 미친 감자의 블로그
- The Art of Assembly Language
- Chpie (키보드 후킹)
- Drivers Online
- (음악) Delicate SONG
- Reverse Engineering Community
- Software Best Practices
- Sara Ford's WebLog
- Cheat Happens
- Debugging,Unpacking,Assembling…
- 윤석찬님 블로그
- OK 괜찮아 다 잘 될거야
- RingBlog
- Art Life :: 하늘소
- IT's Paradise
- John Robbins!
- Wintellect
- Hacked Gadgets
- 소프트웨어 이야기
- Ryan Naraine's Zero Day
- VULN
- Stay Secure
- EBS 영어 공부(블루워터)
- 101BLoG : "Bright Size Life" o…
- Hacker Challenge
- Hackers Center
- White Hat, Chicago Con
- Ethical Hacker Network
- ChaseNet (Security)
- TechTarget
- Entrepreneur
- Infopackets
- Popular Science
- Dark Reading - The Business of…
- How Stuff Works
- codeDriver - Crack (역공학)
- Gadget (Windows)
- Serious Code
- Iguacu Blog(블루문)
- SecurityProof
- Power of Community(Hacker)
- Crack ?
- Security Freak
- Data Network Resource
- FoundStone - Security Consulti…
- Google Online Security Blog
- (BOOK) Cool DogBooks
- SachaBarber (좋은 개발자)
- System Software Incorporation
- 스카이 벤처
- NewsTorrent
- 글로벌 IT 네트워크
- Ethical Hacking and Infosec
- Realms of Hacking tricks
- CodeBreakers Journal
- Anti Rootkit Blog
- The Reverse Code Engineering C…
- Anti-Debug Tools
- Reverse Code Engineering Video…
- Damn Vulnerable linux
- Security Problems
- French Reverse Engineering Tea…
- Monac
- Open Source Vulnerability Data…
- Viruschaser 검사(바이러스)
- Windows Tips
- 보안 대처 연습
- [Download] Kartz CD
- [Download] FlMS Download
- [Download] DDL2
- 중국 해킹 사이트(안전중국)
- 바이러스 분석
- Javascript 전문가
- Virus Alert Zone (바이러스 분석)
- Computer World
- 문스랩닷컴(보안)
- Unpack China
- Black Storm Reverse Engineerin…
- 역공학 Reverser
- 문화 망명지 - 시, 소설
- WPF MVP
- Research Channel
- The Problem Solver - C# MVP
- Reversing - 리버스 엔지니어링
- Nigel Spencer's Blog (.NET)
- Kirill Osenkov (.NET C# IDE Te…
- H33T (BitTorrnet 검색 사이트)
- ITL (해킹, 보안)
- ITL (Invisible Things Lab) Blo…
- ebook, pdf, chm
- 주식 - 멘토클리닉
- CherryLove - 바이러스, 백신, 악성코드
- PMP
- 영원한 해커, hacker
- 리버싱, PE
- 신호철 - dsphome
- TechEd 2009
- SHOUT
- [도서] 오디오북
- [도서] 전자책
- [도서] 국내도서요약
- [도서] 해외도서요약
- TopCorder - 프로그래밍 연습
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 |
30 | 31 |
- WPF
- Microsoft
- 마이크로소프트
- VSTS
- debugging
- MVP
- 닷넷
- Windows
- 구글
- 보안
- 책
- 비주얼스튜디오
- english
- 역공학
- VSTS 2010
- C#
- 해킹
- hacking
- security
- visual studio 2010
- 비주얼 스튜디오
- .net
- 디버그랩
- 디버깅
- .NET Framework
- .net framework 4
- Visual Studio
- Windows 7
- Today
- Total
NaggingMachine
Java의 ThreadLocal 사용해서 Singleton 구현하기 본문
아주 아주 오랫만에 기술 자료 공유, 혹시나 참고하실 만한 분이 있을까 싶어서 올립니다.
Singleton 구조에서 스레드를 사용하면 데이터가 꼬이게 되는데, 그걸 ThreadLocal로 막을 수가 있더군요. 물론 Singleton을 반드시 사용해야 하는 경우에만 해당됩니다.
소스 코드는 첨부했어요. 테스트만 해보려고 만들었습니다. ^^
감사합니다~!
public class ThreadLocalTestMain implements Runnable {
public static void main(String[] args) {
ThreadLocalTestMain r = new ThreadLocalTestMain();
Thread t1 = new Thread(r);
Thread t2 = new Thread(r);
Thread t3 = new Thread(r);
t1.start();
t2.start();
t3.start();
}
// 이건 전통적인 Singleton
public void run() {
Singleton2 obj = Singleton2.getInstance();
while(true) {
obj._count++;
System.out.println(String.format("%d: %d", Thread.currentThread().getId(), obj._count));
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
// 이건 ThreadLocal을 적용한 Singleton
// public void run() {
// ThreadLocal<Singleton> instance = Singleton.getInstance();
// Singleton obj = instance.get();
//
// while(true) {
// obj._count++;
// System.out.println(String.format("%d: %d", Thread.currentThread().getId(), obj._count));
// try {
// Thread.sleep(100);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
//
// }
}
public class Singleton {private static ThreadLocal<Singleton> _instance;public int _count;public static ThreadLocal<Singleton> getInstance() {if (_instance == null) {_instance = new ThreadLocal<Singleton>(){@Overridepublic Singleton initialValue() {return new Singleton();}};}return _instance;}}
public class Singleton2 {private static Singleton2 _instance;public int _count;public static Singleton2 getInstance() {if (_instance == null) {_instance = new Singleton2();}return _instance;}}
'TechnoBabbler' 카테고리의 다른 글
간단하게 사용하는 iOS용 HTTP 요청 예제 (0) | 2013.04.08 |
---|---|
Rest API용 자동 Test Case 만들기 (0) | 2013.03.22 |
JQuery Timer 사용 (0) | 2012.01.16 |
JQuery에서 동적으로 객체 바인딩하기 (0) | 2012.01.16 |
Volunteer Computing에 대한 회상 (0) | 2012.01.09 |