티스토리 뷰
public class InterruptTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
ThreadInterrupt th = new ThreadInterrupt("Thread");
th.start();
try {
Thread.sleep(2000);
th.interrupt(); //2초 뒤 인터럽트
} catch (InterruptedException e) {
}
}
}
class ThreadInterrupt extends Thread {
ThreadInterrupt(String str) {
super(str);
}
public void run() {
try {
for (int i = 0; i < 10; i++) {
Thread.sleep(500);
System.out.println(getName() + " " + i + "번째 수행");
}
} catch (InterruptedException e) {
System.out.println("스레드 강제 종료");
//인터럽트 예외를 받는다.
return;
}
}
}
결과 :
Thread 0번째 수행
Thread 1번째 수행
Thread 2번째 수행
Thread 3번째 수행
스레드 강제 종료
'java,web study > 3주차 (7월 15일 ~21일)' 카테고리의 다른 글
Migration (0) | 2013.07.17 |
---|---|
멀티스레드 (0) | 2013.07.17 |
데몬 스레드 (0) | 2013.07.17 |
스레드 예제 (성금 모금) (0) | 2013.07.17 |
스레드 예제 (Bank) (0) | 2013.07.17 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 소켓
- CSS
- 메모장
- 파이썬
- jsp
- 오라클
- 졸업작품
- 프로젝트
- JQuery
- HTML
- 자바스크립트
- 정렬
- 안드로이드
- 자바
- ERP
- 데이터베이스
- 게임
- 정보
- 클래스
- 아두이노
- 알고리즘
- SVN
- 청주
- db
- 이론
- 도전과제
- 잡담
- 배열
- 충북대
- SQL
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함