develog

synchronized 본문

Dev/Java

synchronized

냐옴 2013. 3. 17. 11:43

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
Comments