-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadPriorityTest.java
More file actions
46 lines (38 loc) · 1 KB
/
ThreadPriorityTest.java
File metadata and controls
46 lines (38 loc) · 1 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package thread;
class MyThread extends Thread{
@Override
public void run() {
// TODO Auto-generated method stub
// 시간 지연을 위한 코드 - 프로그램이 실행되는 시간을 표현
for ( int i = 0 ; i <= 100000000 ; i ++) {
}
System.out.println(getName()+"쓰레드의 우선순위->"+getPriority());
}
}
public class ThreadPriorityTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
// 숫자가 클수록 우선수위가 높다
System.out.println(Thread.MAX_PRIORITY);
System.out.println(Thread.NORM_PRIORITY);
System.out.println(Thread.MIN_PRIORITY);
for ( int i = 1 ; i<=3 ; i++) {
MyThread t= new MyThread();
t.start();
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for ( int i = 1 ; i<=10 ; i++) {
MyThread t= new MyThread();
t.setName("t"+i);
if ( i == 7 ) {
t.setPriority(Thread.MAX_PRIORITY);
}
t.start();
}
}
}