Giter VIP home page Giter VIP logo

java-concurrency's Introduction

Java concurrency 예제

예제 출처

장별 예제 정리 링크

3. java.lang.Thread 바로 알기

4. 동기화와 가시성

  • Sychronized
    • NonreentrantDeadlock.java : synchronized 키워드에 의한 lock은 재진입가능하다는 것을 보여줌
    • SyncDemo.java : synchronized로 선언된 Block이 동시에 실행되지 못함을 보여줌.
    • PingPong.java : static method의 syncronized 키워드의 동작방식을 보여줌.
  • 가시성 확보
    • StopThread.java(Broken) : static 변수이지만 가시성 확보가 안 되어서 한 스레드에서 write한 값이 다른 thread에서 안 보이는 현상을 보여줌.
    • StopThread.java(Fix1) : 가시성 문제를 synchronized 메소드를 이용해서 동기화 시켜서 해결
    • StopThread.java(Fix2) : 가시성 문제를 volatile 키워드를 이용해서 해결
    • Worker.java : 가시성 확보, 동기화를 모두 했음에도 Thread.join이 호출되면 예상치 못한 동작이 발생함을 보여줌

5. Java concurrent API

  • Executors
    • TimingThreadPool.java : ThreadPoolExecutor를 확장해서 시간측정 로깅 기능을 추가한 예제
  • Callable
    • Preloader.java : Callable, FutureTask , Thread 생성, Future.get의 사용예.
  • java.util.concurrent.locks패키지
  • CountDownLatch
    • TestHarness.java : CountDownLatch를 이용해서 여러 쓰레드로 작업을 실행하고, 최종 종료시간을 구함
    • ConcurrentTimer.java : TestHarness와 유사한 역할이나 스레드 생성 후에 실행되는 구간을 측정하기 위해 단계를 하나 더 두었음.
  • Semaphore
  • 다양한 동기화 방식

6. Thread 안전 클래스

  • Iterator

  • BlockingQueue

  • Atomic class

  • 설계 원칙

    • StackDemo.java : 쓰레드에 한정되어야할 객체를 콜스택 안에서 local변수로 생성하여 메소드 파라미터로 넘김.
    • ThreadLocalDemo.java : ThreadLocal을 이용.

7. Documentation

  • JCIP annotation
    • Memo.java : @Immutable로 선언했을 때 Findbugs를 경고를 보여줌
    • LoginInfo.java : Thread-safe하지 않은 클래스
    • UserService.java : Thread-safe하지 않은 클래스를 멤버변수로 사용하는 코드

8. 성능

java-concurrency's People

Contributors

benelog avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.