IT박스

'동기화 됨'은 무엇을 의미합니까?

itboxs 2020. 9. 28. 08:32
반응형

'동기화 됨'은 무엇을 의미합니까?


synchronized키워드 의 사용법과 의미에 대해 몇 가지 질문이 있습니다 .

  • synchronized키워드 의 의미는 무엇입니까 ?
  • 메소드는 언제해야 synchronized합니까?
  • 프로그래밍 방식 및 논리적으로 무엇을 의미합니까?

synchronized키워드는 읽기와 같은 변수, 객체, 자원에 쓰는 다른 스레드에 대한 모든 것입니다. 이것은 Java에서 사소한 주제가 아니지만 다음은 Sun의 인용문입니다.

synchronized 메서드를 사용하면 스레드 간섭 및 메모리 일관성 오류를 방지하기위한 간단한 전략을 사용할 수 있습니다. 개체가 둘 이상의 스레드에 표시되면 해당 개체의 변수에 대한 모든 읽기 또는 쓰기가 동기화 된 메서드를 통해 수행됩니다.

아주 아주 작은 요약 : 동일한 '자원'을 읽고 쓰는 두 개의 스레드 (예 : 라는 foo변수)가있는 경우 이러한 스레드가 원자 적 방식으로 변수에 액세스하는지 확인해야합니다. synchronized키워드가 없으면 스레드 1이 변경 스레드 2가으로 foo변경된 것을 볼 수 없거나 더 나쁜 경우 절반 만 변경 될 수 있습니다. 이것은 논리적으로 기대하는 것이 아닙니다.

다시 말하지만 이것은 Java에서 사소한 주제가 아닙니다. 자세한 내용은 여기 SO 및 Interwebs에 대한 주제를 탐색하십시오.

"Brian Goetz" 라는 이름 두뇌의 "동시성" 이라는 용어와 영구적으로 연관 될 때까지이 주제를 계속 탐색하십시오 .


글쎄, 우리는 이론적 인 설명이 충분하다고 생각합니다.

public class SOP {
    public static void print(String s) {
        System.out.println(s+"\n");
    }
}

public class TestThread extends Thread {
    String name;
    TheDemo theDemo;
    public TestThread(String name,TheDemo theDemo) {
        this.theDemo = theDemo;
        this.name = name;
        start();
    }
    @Override
    public void run() {
        theDemo.test(name);
    }
}

public class TheDemo {
    public synchronized void test(String name) {
        for(int i=0;i<10;i++) {
            SOP.print(name + " :: "+i);
            try{
                Thread.sleep(500);
            } catch (Exception e) {
                SOP.print(e.getMessage());
            }
        }
    }
    public static void main(String[] args) {
        TheDemo theDemo = new TheDemo();
        new TestThread("THREAD 1",theDemo);
        new TestThread("THREAD 2",theDemo);
        new TestThread("THREAD 3",theDemo);
    }
}

참고 : synchronized이전 스레드의 실행이 완료되지 않는 한 test () 메서드에 대한 다음 스레드의 호출을 차단합니다. 스레드는이 메서드에 한 번에 하나씩 액세스 할 수 있습니다. synchronized모든 스레드가 없으면 이 메서드에 동시에 액세스 할 수 있습니다.

스레드가 개체의 동기화 된 메서드 'test'를 호출하면 (여기서 개체는 'TheDemo'클래스의 인스턴스입니다) 해당 개체의 잠금을 획득하고, 새 스레드는 이전 스레드만큼 동일한 개체의 동기화 된 메서드를 호출 할 수 없습니다. 잠금을 획득 한 것은 잠금을 해제하지 않습니다.

클래스의 정적 동기화 메서드가 호출 될 때 비슷한 일이 발생합니다. 스레드는 클래스와 연관된 잠금을 획득합니다 (이 경우 해당 객체 수준 잠금을 계속 사용할 수 있으므로 해당 클래스의 인스턴스에 대한 비 정적 동기화 메서드를 모든 스레드에서 호출 할 수 있음). 현재 잠금을 보유하고있는 스레드에 의해 클래스 수준 잠금이 해제되지 않는 한 다른 스레드는 클래스의 정적 동기화 메서드를 호출 할 수 없습니다.

동기화 된 출력

THREAD 1 :: 0
THREAD 1 :: 1
THREAD 1 :: 2
THREAD 1 :: 3
THREAD 1 :: 4
THREAD 1 :: 5
THREAD 1 :: 6
THREAD 1 :: 7
THREAD 1 :: 8
THREAD 1 :: 9
THREAD 3 :: 0
THREAD 3 :: 1
THREAD 3 :: 2
THREAD 3 :: 3
THREAD 3 :: 4
THREAD 3 :: 5
THREAD 3 :: 6
THREAD 3 :: 7
THREAD 3 :: 8
THREAD 3 :: 9
THREAD 2 :: 0
THREAD 2 :: 1
THREAD 2 :: 2
THREAD 2 :: 3
THREAD 2 :: 4
THREAD 2 :: 5
THREAD 2 :: 6
THREAD 2 :: 7
THREAD 2 :: 8
THREAD 2 :: 9

동기화되지 않은 출력

THREAD 1 :: 0
THREAD 2 :: 0
THREAD 3 :: 0
THREAD 1 :: 1
THREAD 2 :: 1
THREAD 3 :: 1
THREAD 1 :: 2
THREAD 2 :: 2
THREAD 3 :: 2
THREAD 1 :: 3
THREAD 2 :: 3
THREAD 3 :: 3
THREAD 1 :: 4
THREAD 2 :: 4
THREAD 3 :: 4
THREAD 1 :: 5
THREAD 2 :: 5
THREAD 3 :: 5
THREAD 1 :: 6
THREAD 2 :: 6
THREAD 3 :: 6
THREAD 1 :: 7
THREAD 2 :: 7
THREAD 3 :: 7
THREAD 1 :: 8
THREAD 2 :: 8
THREAD 3 :: 8
THREAD 1 :: 9
THREAD 2 :: 9
THREAD 3 :: 9

synchronized키워드는 여러 스레드 코드 또는 객체의 블록에 대한 동시 액세스를 방지합니다. 기본적으로 a Hashtablesynchronized이므로 한 번에 하나의 스레드 만 테이블에 액세스 할 수 있습니다.

의 사용에 대한 non-synchronized구조가 좋아 HashMap, 당신은 스레드 안전 메모리 일관성 오류를 방지하기 위해 코드에 기능을 구축해야합니다.


synchronized다중 스레드 환경에서 synchronized메서드 / 블록을 가진 객체 는 두 개의 스레드가 synchronized코드 메서드 / 블록에 동시에 액세스 할 수 없도록합니다. 이것은 다른 스레드가 그것을 업데이트하는 동안 한 스레드가 읽을 수 없음을 의미합니다.

두 번째 스레드는 대신 첫 번째 스레드가 실행을 완료 할 때까지 기다립니다. 오버 헤드는 속도이지만 데이터의 일관성이 보장되는 이점이 있습니다.

응용 프로그램이 단일 스레드 인 경우 synchronized블록은 이점을 제공하지 않습니다.


synchronized키워드 방식을 입력 할 때 (이 정적 메소드가 아니면, 지정된 객체 인스턴스에 대한) 단 하나 개의 스레드가 동시에 상기 방법을 실행할 수 있도록하는 것이, 로크를 획득하기 위해 스레드를 야기한다.

이것은 클래스를 스레드로부터 안전하게 만드는 것으로 자주 불려지지만 완곡 어법이라고 말하고 싶습니다. 동기화가 Vector의 내부 상태가 손상되지 않도록 보호하는 것은 사실이지만 일반적으로 Vector 사용자에게는 큰 도움이되지 않습니다.

이걸 고려하세요:

 if (vector.isEmpty()){
     vector.add(data);
 }

관련된 메서드가 동기화되어 있더라도 개별적으로 잠기고 잠금 해제되기 때문에 불행히도 시간이 지정된 두 스레드는 두 요소가있는 벡터를 만들 수 있습니다.

따라서 실제로 응용 프로그램 코드에서도 동기화해야합니다.

메서드 수준 동기화는 a) 필요하지 않을 때는 비용이 많이 들고 b) 동기화가 필요할 때는 불충분하기 때문에 이제 동기화되지 않은 대체 항목이 있습니다 (Vector의 경우 ArrayList).

최근에는 멀티 스레딩 문제를 처리하는 여러 영리한 유틸리티와 함께 ​​동시성 패키지가 출시되었습니다.


개요

Java의 Synchronized 키워드는 스레드 안전성, 즉 여러 스레드가 동일한 변수를 읽거나 쓸 때와 관련이 있습니다.
이는 직접 (동일한 변수에 액세스하여) 또는 간접적으로 (동일한 변수에 액세스하는 다른 클래스를 사용하는 클래스를 사용하여) 발생할 수 있습니다.

동기화 된 키워드는 여러 스레드가 안전한 방식으로 동일한 변수에 액세스 할 수있는 코드 블록을 정의하는 데 사용됩니다.

더 깊게

구문 측면에서 synchronized키워드는 Object그대로 매개 변수 ( 잠금 객체 라고 함)를 취한 다음 { block of code }.

  • 실행이이 키워드를 만나면 현재 스레드는 잠금 개체 를 "잠금 / 획득 / 소유"(선택)하고 잠금을 획득 한 후 관련 코드 블록을 실행 하려고합니다 .

  • 동기화 된 코드 블록 내의 변수에 대한 쓰기는 동일한 잠금 개체를 사용하여 동기화 된 코드 블록 내의 코드를 유사하게 실행하는 다른 모든 스레드에서 볼 수 있도록 보장됩니다 .

  • 한 번에 하나의 스레드 만 잠금을 유지할 수 있으며 그 동안 동일한 잠금 개체 를 얻으려는 다른 모든 스레드 가 대기합니다 (실행 일시 중지). 실행이 동기화 된 코드 블록을 종료하면 잠금이 해제됩니다.

동기화 된 방법 :

synchronized메서드 정의에 키워드를 추가 하는 것은 잠금 개체this (인스턴스 메서드)ClassInQuestion.getClass() (클래스 메서드) 인 동기화 된 코드 블록에 래핑 된 전체 메서드 본문과 같습니다 .

-인스턴스 방식은 static키워드 가없는 방식입니다 .
-클래스 방식은 static키워드 가있는 방식입니다 .

전문인

동기화가 없으면 읽기 및 쓰기가 발생하는 순서가 보장되지 않으며 변수에 가비지가 남을 수 있습니다.
(예를 들어, 변수는 한 스레드가 쓴 비트의 절반과 다른 스레드가 쓴 비트의 절반으로 끝날 수 있으며,이 변수는 스레드가 쓰려고하지 않은 상태로 남겨두고 둘 다 섞인 상태로 남게됩니다.)

하드웨어가 변수 값을 캐시 할 수 있고 읽기 스레드가 기록 된 값 대신 캐시 된 값을 볼 수 있기 때문에 다른 스레드가 읽기 전에 (벽시계 시간) 스레드에서 쓰기 작업을 완료하는 것만으로는 충분하지 않습니다. 그것.

결론

따라서 자바의 경우 스레딩 오류가 발생하지 않도록 자바 메모리 모델을 따라야합니다.
즉, 동기화, 원자 적 작업 또는 내부적으로이를 사용하는 클래스를 사용하십시오.

출처

http://docs.oracle.com/javase/specs/jls/se8/html/index.html
Java® 언어 사양, 2015-02-13


축구장에서 찾을 수있는 일종의 개찰구라고 생각하면됩니다. 들어 가고자하는 사람들의 평행 한 증기가 있지만 개찰구에서는 '동기화'됩니다. 한 번에 한 사람 만 통과 할 수 있습니다. 통과하고자하는 모든 사람들은 그렇게 할 것이지만 통과 할 수있을 때까지 기다려야 할 수도 있습니다.


동기화 된 키워드는 무엇입니까?

스레드는 주로 필드 및 개체 참조 필드에 대한 액세스를 공유하여 통신합니다. 이러한 형태의 통신은 매우 효율적이지만 스레드 간섭 및 메모리 일관성 오류 의 두 가지 오류를 가능하게 합니다 . 이러한 오류를 방지하는 데 필요한 도구는 동기화입니다.

동기화 된 블록 또는 메서드는 스레드 간섭을 방지하고 데이터의 일관성을 보장합니다. 어느 시점에서든 하나의 스레드 만 잠금을 획득하여 동기화 된 블록 또는 메소드 ( 임계 섹션 )에 액세스 할 수 있습니다 . 다른 스레드는 중요한 섹션 에 액세스하기 위해 잠금 해제를 기다립니다 .

메소드는 언제 동기화됩니까?

메서드 synchronized정의 또는 선언에 추가하면 메서드가 동기화됩니다 . 메서드 내에서 특정 코드 블록을 동기화 할 수도 있습니다.

그것은 프로그램 적으로 그리고 논리적으로 무엇을 의미합니까?

이는 하나의 스레드 만 잠금을 획득하여 중요 섹션액세스 할 수 있음을 의미합니다 . 이 스레드가이 잠금을 해제하지 않는 한, 다른 모든 스레드는 잠금을 획득하기 위해 기다려야합니다. 잠금을 획득 하지 않고 중요한 섹션 에 들어갈 수 없습니다 .

이것은 마법으로 할 수 없습니다. 응용 프로그램에서 중요한 섹션 을 식별 하고 그에 따라 보호하는 것은 프로그래머의 책임 입니다. Java는 애플리케이션을 보호하는 프레임 워크를 제공하지만 보호 할 모든 섹션의 위치와 내용은 프로그래머의 책임입니다.

Java 문서 페이지 에서 자세한 내용

고유 잠금 및 동기화 :

동기화는 고유 잠금 또는 모니터 잠금으로 알려진 내부 엔티티를 중심으로 구축됩니다. 내부 잠금은 동기화의 두 가지 측면에서 역할을합니다. 객체 상태에 대한 배타적 액세스를 적용하고 가시성에 필수적인 관계를 설정하기 전에 발생합니다.

모든 개체에는 연결된 고유 잠금이 있습니다 . 관례 상, 객체의 필드에 대한 독점적이고 일관된 액세스가 필요한 스레드는 객체에 액세스하기 전에 객체의 고유 잠금을 획득 한 다음 작업이 완료되면 고유 잠금을 해제해야합니다.

스레드는 잠금을 획득하고 잠금을 해제 한 시간 사이에 고유 잠금을 소유한다고합니다. 스레드가 고유 잠금을 소유하는 한 다른 스레드는 동일한 잠금을 획득 할 수 없습니다. 다른 스레드는 잠금을 획득하려고 할 때 차단됩니다.

스레드가 고유 잠금을 해제하면 해당 작업과 동일한 잠금의 후속 획득간에 사전 발생 관계가 설정됩니다.

메서드를 동기화하면 두 가지 효과가 있습니다 .

첫째, 동일한 개체에서 동기화 된 메서드를 두 번 호출하여 인터리브 할 수 없습니다.

한 스레드가 개체에 대해 동기화 된 메서드를 실행할 때 첫 번째 스레드가 개체에 대해 완료 될 때까지 동일한 개체 블록 (실행 일시 중단)에 대해 동기화 된 메서드를 호출하는 다른 모든 스레드입니다.

둘째, 동기화 된 메서드가 종료되면 동일한 개체에 대해 동기화 된 메서드의 후속 호출과 함께 사전 발생 관계를 자동으로 설정합니다.

이렇게하면 개체 상태의 변경 사항이 모든 스레드에 표시됩니다.

에서 동기화에 대한 다른 대안을 찾으십시오.

Java에서 동기화 (this)를 피합니까?


다음은 The Java Tutorials의 설명 입니다.

다음 코드를 고려하십시오.

public class SynchronizedCounter {
    private int c = 0;

    public synchronized void increment() {
        c++;
    }

    public synchronized void decrement() {
        c--;
    }

    public synchronized int value() {
        return c;
    }
}

count의 인스턴스 인 경우 SynchronizedCounter이러한 메서드를 동기화하면 두 가지 효과가 있습니다.

  • 첫째, 동일한 개체에서 동기화 된 메서드를 두 번 호출하여 인터리브 할 수 없습니다. 한 스레드가 개체에 대해 동기화 된 메서드를 실행할 때 첫 번째 스레드가 개체에 대해 완료 될 때까지 동일한 개체 블록 (실행 일시 중단)에 대해 동기화 된 메서드를 호출하는 다른 모든 스레드입니다.
  • 둘째, 동기화 된 메서드가 종료되면 동일한 개체에 대해 동기화 된 메서드의 후속 호출과 함께 사전 발생 관계를 자동으로 설정합니다. 이렇게하면 개체 상태의 변경 사항이 모든 스레드에 표시됩니다.

내 이해에 동기화는 기본적으로 컴파일러가 메서드 주위에 monitor.enter 및 monitor.exit를 작성한다는 것을 의미합니다. 따라서 사용 방법에 따라 스레드로부터 안전 할 수 있습니다 (즉, 클래스가 수행하는 작업에 따라 스레드로부터 안전하지 않은 동기화 된 메서드로 개체를 작성할 수 있음을 의미합니다).


Synchronized normal method에 해당 Synchronized statement(사용)

class A {
    public synchronized void methodA() {
        // all function code
    }

    equivalent to

    public void methodA() {
        synchronized(this) {
             // all function code
        }
    } 
}

Synchronized static method동등 Synchronized statement(클래스 사용)

class A {
    public static synchronized void methodA() {
        // all function code
    }

    equivalent to

    public void methodA() {
        synchronized(A.class) {
             // all function code
        }
    } 
}

동기화 된 문 (변수 사용)

class A {
    private Object lock1 = new Object();

    public void methodA() {
        synchronized(lock1 ) {
             // all function code
        }
    } 
}

를 들어 synchronized, 우리는 모두 가지고 Synchronized MethodsSynchronized Statements. 그러나과 Synchronized Methods유사 Synchronized Statements하므로 Synchronized Statements.

=> 기본적으로 우리는

synchronized(object or class) { // object/class use to provides the intrinsic lock
   // code 
}

여기 2 이해에 도움이되는 생각입니다 synchronized

  • 모든 객체 / 클래스에는 intrinsic lock관련이 있습니다.
  • 스레드가를 호출 synchronized statement하면 자동으로 intrinsic lock해당 synchronized statement's객체에 대한를 획득 하고 메서드가 반환 될 때 해제합니다. 한 스레드가 소유으로 intrinsic lock, 다른 스레드는 얻을 수 없다 SAME 잠금 => 스레드 금고.

=> thread A호출시 synchronized(this){// code 1}=> have synchronized(this)와 all synchronized normal method(inside class)이있는 모든 블록 코드 (inside class)는 SAME lock 때문에 잠 깁니다. thread A잠금 해제 ( "// 코드 1"완료) 후에 실행됩니다 .

이 동작은 유사하다 synchronized(a variable){// code 1}synchronized(class).

SAME LOCK => 잠금 (어떤 방법이나 어떤 문에 의존하지 않습니까?)

동기화 된 방법 또는 동기화 된 문을 사용합니까?

I prefer synchronized statements because it is more extendable. Example, in future, you only need synchronized a part of method. Example, you have 2 synchronized method and it don't have any relevant to each other, however when a thread run a method, it will block the other method (it can prevent by use synchronized(a variable)).

However, apply synchronized method is simple and the code look simple. For some class, there only 1 synchronized method, or all synchronized methods in the class in relevant to each other => we can use synchronized method to make code shorter and easy to understand

Note

(it not relevant to much to synchronized, it is the different between object and class or none-static and static).

  • When you use synchronized or normal method or synchronized(this) or synchronized(non-static variable) it will synchronized base on each object instance.
  • When you use synchronized or static method or synchronized(class) or synchronized(static variable) it will synchronized base on class

Reference

https://docs.oracle.com/javase/tutorial/essential/concurrency/syncmeth.html https://docs.oracle.com/javase/tutorial/essential/concurrency/locksync.html

Hope it help


What the other answers are missing is one important aspect: memory barriers. Thread synchronization basically consists of two parts: serialization and visibility. I advise everyone to google for "jvm memory barrier", as it is a non-trivial and extremely important topic (if you modify shared data accessed by multiple threads). Having done that, I advise looking at java.util.concurrent package's classes that help to avoid using explicit synchronization, which in turn helps keeping programs simple and efficient, maybe even preventing deadlocks.

One such example is ConcurrentLinkedDeque. Together with the command pattern it allows to create highly efficient worker threads by stuffing the commands into the concurrent queue -- no explicit synchronization needed, no deadlocks possible, no explicit sleep() necessary, just poll the queue by calling take().

In short: "memory synchronization" happens implicitly when you start a thread, a thread ends, you read a volatile variable, you unlock a monitor (leave a synchronized block/function) etc. This "synchronization" affects (in a sense "flushes") all writes done before that particular action. In the case of the aforementioned ConcurrentLinkedDeque, the documentation "says":

Memory consistency effects: As with other concurrent collections, actions in a thread prior to placing an object into a ConcurrentLinkedDeque happen-before actions subsequent to the access or removal of that element from the ConcurrentLinkedDeque in another thread.

This implicit behavior is a somewhat pernicious aspect because most Java programmers without much experience will just take a lot as given because of it. And then suddenly stumble over this thread after Java isn't doing what it is "supposed" to do in production where there is a different work load -- and it's pretty hard to test concurrency issues.


Synchronized simply means that multiple threads if associated with single object can prevent dirty read and write if synchronized block is used on particular object. To give you more clarity , lets take an example :

class MyRunnable implements Runnable {
    int var = 10;
    @Override
    public void run() {
        call();
    }

    public void call() {
        synchronized (this) {
            for (int i = 0; i < 4; i++) {
                var++;
                System.out.println("Current Thread " + Thread.currentThread().getName() + " var value "+var);
            }
        }
    }
}

public class MutlipleThreadsRunnable {
    public static void main(String[] args) {
        MyRunnable runnable1 = new MyRunnable();
        MyRunnable runnable2 = new MyRunnable();
        Thread t1 = new Thread(runnable1);
        t1.setName("Thread -1");
        Thread t2 = new Thread(runnable2);
        t2.setName("Thread -2");
        Thread t3 = new Thread(runnable1);
        t3.setName("Thread -3");
        t1.start();
        t2.start();
        t3.start();
    }
}

We've created two MyRunnable class objects , runnable1 being shared with thread 1 and thread 3 & runnable2 being shared with thread 2 only. Now when t1 and t3 starts without synchronized being used , PFB output which suggest that both threads 1 and 3 simultaneously affecting var value where for thread 2 , var has its own memory.

Without Synchronized keyword

    Current Thread Thread -1 var value 11
    Current Thread Thread -2 var value 11
    Current Thread Thread -2 var value 12
    Current Thread Thread -2 var value 13
    Current Thread Thread -2 var value 14
    Current Thread Thread -1 var value 12
    Current Thread Thread -3 var value 13
    Current Thread Thread -3 var value 15
    Current Thread Thread -1 var value 14
    Current Thread Thread -1 var value 17
    Current Thread Thread -3 var value 16
    Current Thread Thread -3 var value 18

Using Synchronzied, thread 3 waiting for thread 1 to complete in all scenarios. There are two locks acquired , one on runnable1 shared by thread 1 and thread 3 and another on runnable2 shared by thread 2 only.

Current Thread Thread -1 var value 11
Current Thread Thread -2 var value 11
Current Thread Thread -1 var value 12
Current Thread Thread -2 var value 12
Current Thread Thread -1 var value 13
Current Thread Thread -2 var value 13
Current Thread Thread -1 var value 14
Current Thread Thread -2 var value 14
Current Thread Thread -3 var value 15
Current Thread Thread -3 var value 16
Current Thread Thread -3 var value 17
Current Thread Thread -3 var value 18

synchronized simple means no two threads can access the block/method simultaneously. When we say any block/method of a class is synchronized it means only one thread can access them at a time. Internally the thread which tries to access it first take a lock on that object and as long as this lock is not available no other thread can access any of the synchronized methods/blocks of that instance of the class.

Note another thread can access a method of the same object which is not defined to be synchronized. A thread can release the lock by calling

Object.wait()

I like the Jenkov's explanation

synchronized

Synchronized blocks in Java are marked with the synchronized keyword. A synchronized block in Java is synchronized on some object. All synchronized blocks synchronized on the same object can only have one thread executing inside them at the same time. All other threads attempting to enter the synchronized block are blocked until the thread inside the synchronized block exits the block.

happens-before[About]

An unlock (synchronized block or method exit) of a monitor happens-before every subsequent lock (synchronized block or method entry) of that same monitor.

Synchronized blocks guarantee that when the thread exits the synchronized block all updated variables will be flushed into to main memory and all variables accessed inside the synchronized block will be read in from main memory.

From Java 5

Java Concurrency Utilities

The synchronized mechanism was Java's first mechanism for synchronizing access to objects shared by multiple threads. The synchronized mechanism isn't very advanced though. That is why Java 5 got a whole set of concurrency utility classes to help developers implement more fine grained concurrency control than what you get with synchronized.


synchronized is a keyword in Java which is used to make happens before relationship in multithreading environment to avoid memory inconsistency and thread interference error.

참고URL : https://stackoverflow.com/questions/1085709/what-does-synchronized-mean

반응형