일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- CSS
- 웹
- orcle
- UI
- DB
- 코딩
- html
- Project
- ERWin
- 객체지향
- 객체지향프로그래밍
- 데이터베이스
- 객제지향프로그래밍
- sql
- jsp
- squery
- 프로젝트
- web
- 공부를열심히
- 프로그래밍
- 웹프로그래밍
- Oracle
- javascript
- 테이블
- 자바
- 주말이다..
- 공부
- 오라클
- 객제지향
- Java
Archives
- Today
- Total
햄찌개
JAVA - 쓰레드 우선순위 본문
public class T08_ThreadPrioityTest {
public static void main(String[] args) {
Thread th1 = new Thread1();
Thread th2 = new Thread2();
//우선 순위는 start() 메서드를 호출하기 전에 설정해야한다.
th1.setPriority(10); //setPriority() 우선순위 정해주는것 파라미터로 1~10 정수 가능
th2.setPriority(1); //10이 최우선
System.out.println("th1의 우선순위 : "+th1.getPriority());
System.out.println("th2의 우선순위 : "+th2.getPriority());
th1.start();
th2.start();
try {
th1.join();
th2.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("최대 우선순위 : "+Thread.MAX_PRIORITY );
System.out.println("최소 우선순위 : "+Thread.MIN_PRIORITY );
System.out.println("보통 우선순위 : "+Thread.NORM_PRIORITY );
}
}
// 대문자를 출력하는 쓰레드
class Thread1 extends Thread {
@Override
public void run() {
for (char ch = 'A'; ch <= 'Z'; ch++) {
System.out.println(ch);
// 아무것도 하지 않는 반복문 (시간 떄우기용)
for (long i = 1L; i < 1000000000L; i++) {
}
}
}
}
// 소문자를 출력하는 쓰레드
class Thread2 extends Thread {
@Override
public void run() {
for (char ch = 'a'; ch <= 'z'; ch++) {
System.out.println(ch);
// 아무것도 하지 않는 반복문 (시간 떄우기용)
for (long i = 1L; i < 1000000000L; i++) {
}
}
}
}
'고급 JAVA' 카테고리의 다른 글
JAVA - 쓰래드 상태 (0) | 2020.09.23 |
---|---|
JAVA - Daemon쓰레드 (0) | 2020.09.23 |
JAVA - 쓰레드 예제 - 가위바위보 (0) | 2020.09.23 |
JAVA - 단일, 멀티 쓰레드 (0) | 2020.09.23 |
JAVA - 쓰레드 수행시간 체크 (0) | 2020.09.23 |