티스토리 뷰
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
- 정보
- 배열
- 클래스
- 메모장
- SQL
- 게임
- HTML
- 파이썬
- 데이터베이스
- 도전과제
- 안드로이드
- 소켓
- 알고리즘
- SVN
- 오라클
- 충북대
- 잡담
- 이론
- ERP
- 자바스크립트
- 아두이노
- 정렬
- CSS
- 프로젝트
- JQuery
- 졸업작품
- jsp
- 자바
- db
- 청주
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함