Skip to content

Latest commit

 

History

History
70 lines (54 loc) · 1.25 KB

exam-08-01.adoc

File metadata and controls

70 lines (54 loc) · 1.25 KB

Exam-8-1. 10개의 thread가 시작 메시지를 출력하고, 2초간 대기 후 종료 메시지를 출력하도록 thread pool을 구성해보자.


과정

  1. Runnable interface를 이용해 시작하고 2초 후 종료하는 Worker class를 정의하자.

    • Constructor에서는 이름을 받는다.

      link:../../example/thread/src/main/java/com/nhnacademy/thread_pool/Worker.java[role=include]
  2. main()에서 thread pool을 생성한다.

    • 크기는 생성될 thread 갯수보다 적게한다.

      link:../../example/thread/src/main/java/com/nhnacademy/thread_pool/Exam01.java[role=include]
  3. Thread pool에 Worker class의 object를 넣는다.

    link:../../example/thread/src/main/java/com/nhnacademy/thread_pool/Exam01.java[role=include]
  4. 모든 작업이 완료될때까지 기다렸다 종료한다.

    link:../../example/thread/src/main/java/com/nhnacademy/thread_pool/Exam01.java[role=include]


Source Code

class Worker

link:../../example/thread/src/main/java/com/nhnacademy/thread_pool/Worker.java[role=include]


class Exam01

link:../../example/thread/src/main/java/com/nhnacademy/thread_pool/Exam01.java[role=include]

[돌아가기](../08.thread_pool.adoc)