Skip to content

Latest commit

 

History

History
40 lines (31 loc) · 787 Bytes

exam-06-02.adoc

File metadata and controls

40 lines (31 loc) · 787 Bytes

Exam-6-2. Exam-6-1에서 발생했던 race condition 문제를 syncrhronized keyword를 이용해 해결해 보자.


과정

  1. 공유 자원인 ShareCount instance의 increment method에 syncrhonized keyword를 적용한다.

    link:../../example/thread/src/main/java/com/nhnacademy/synchronization/exam02/SharedCount.java[role=include]
  2. 실행 후 결과를 확인해 본다.


실행 결과

counter1: started
counter2: started
counter1: terminated
counter2: terminated
sharedCount : 20000

[돌아가기](../06.synchronization.adoc)