thread_seminar

33
Thread 창원대학교 정보통신공학과 Mobile-X 유지용 지도교수 : 박동규 2016.01.12.

Upload: ug-yong

Post on 14-Apr-2017

179 views

Category:

Education


2 download

TRANSCRIPT

Thread창원대학교 정보통신공학과 Mobile-X 유지용

지도교수 : 박동규 2016.01.12.

Definition

시작점과 종료점을 가지는 일련된 하나의 작업 흐름

main() { //main thread start ~~~~~~

} //main thread end

Worker

Process

Program ProcessRun

single-thread Process = resources + thread multi-thread Process = resources + thread + thread + …

Realization & Run

1. Thread 클래스를 상속 class MyThread extends Thread { public void run() { ~~~~~~ } //Thread클래스의 run()을 오버라이딩

}

2. Runnable 인터페이스를 구현 class MyThread implements Runnable { public void run() { ~~~~~~ } //Runnable인터페이스의 추상메서드 run()을 구현

}

Realization & Run

Thread 상속

Runnable 구현

Realization & Run

Thread 상속

Runnable 구현

Realization & Run

public class Thread { private Runnable r; //Runnable을 구현한 클래스의 인스턴스를 참조하기 위한 변수 선언

public Thread(Runnable r) { this.r = r;

} public void run() { if (r != null) r.run(); //Runnable인터페이스를 구현한

} 인스턴스의 run()을 호출

Realization & Run

Realization & Run

Call stack

main

Call stack

mainrun

Call stack

mainstart

Call stack

mainstart

Call stack

mainstart

run

Call stack

main run

Call stack

run

Call stack

run

Call stack

Call stack

Program End

Single-thread

thread start

thread end

Multi-thread

thread start

thread end

thread start

thread start

thread end

thread end

thread create

thread create

Multi-threadSingle-thread

Multi-thread

Multi-threadMulti-thread

Multi-thread

Multi-thread

멀티쓰레딩의 장점

- CPU의 사용률을 향상시킨다.

- 자원을 보다 효율적으로 사용할 수 있다.

- 사용자에 대한 응답성이 향상된다.

- 작업이 분리되어 코드가 간결해진다.

Priority

thread의 실행 종료 순서

Priority

가는데 순서 없다

Priority

void setPriority(int) : thread의 우선순위를 지정 int getPriority() : thread의 우선순위를 반환

public static final int MAX_PRIORITY = 10 : 최대우선순위 public static final int MIN_PRIORITY = 1 : 최소우선순위 public static final int NORM_PRIORITY = 5 : 보통우선순위

Priority

Priority

한수경 자바의 기초문법

정명한 연산자

허서영 클래스

유지용 상속과 인터페이스

김용재 레퍼런스

한수경 패키지와 접근제어

정명한 자료구조 클래스

허서영 오브젝트 클래스

유지용 스레드

만든 사람들

참여업체

Mobile-X

정보시각화연구실 (IVIS lab)

창원대학교 정보통신공학과

창원시 모바일 앱지원센터

도움을 주신 분

박동규 창원대학교 정보통신공학과

김대호 창원대학교 IVIS lab

정수현 창원대학교 Mobile-X