일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Source
- VirtualBox
- JavaScript
- context
- plugin
- bash
- find
- profile
- ssh
- netsh
- import
- GIT
- grep
- tomcat
- Eclipse
- resource
- Quartz
- web.xml
- IntelliJ
- lsof
- Windows
- 단축키
- xargs
- vscode
- port
- 줄바꿈 문자
- 네트워크
- Windows 10
- maVen
- Mac
- Today
- Total
develog
synchronized 본문
http://tutorials.jenkov.com/java-concurrency/synchronized.html
// instance methods (one thread per instance)
public synchronized void add(int value) {
this.count += value;
}
// code blocks inside instance methods
public void add(int value) {
synchronized (this) {
this.count += value;
}
}
// static methods (one thread per class)
public static synchronized void add(int value) {
count += value;
}
// code blocks inside static blocks
public static void add(int value) {
synchronized (MyClass.class) {
count += value;
}
}
-------------------------------------------------------
아래 1, 2번은 동일한 내용
1. public synchronized void methodA() {}
2. public void methodA() { synchronized (this) {} }
아래 3, 4번은 동일한 내용
3. public static synchronized void methodA() {}
4. public static void methodA() { synchronized (getClass()) {} }
'Dev > Java' 카테고리의 다른 글
REST Tutorial (0) | 2013.05.13 |
---|---|
자바 web to web 통신 (0) | 2013.05.07 |
jndi test (0) | 2013.03.01 |
dbcp test (0) | 2013.03.01 |
variable arguments (0) | 2013.02.23 |