-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion55.java
More file actions
35 lines (33 loc) · 981 Bytes
/
Question55.java
File metadata and controls
35 lines (33 loc) · 981 Bytes
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
/* program to demonstrate use of setPriority () method
to set priority of a thread to 1, 10 and normal */
class threadPriority extends Thread {
threadPriority (String str) {
super (str);
}
public void run () {
System.out.println ("Running thread name is " + this.getName ());
System.out.println ("Running thread priority is " + this.getPriority ());
try {
for (int i = 1; i <= 5; i++) {
System.out.println ("Thread " + this.getName () + ": " + i);
Thread.sleep (500);
}
}
catch (InterruptedException ie) {
System.out.println (this.getName () + " interrupted!");
}
}
}
class Question55 {
public static void main(String[] args) {
threadPriority t1 = new threadPriority ("A");
threadPriority t2 = new threadPriority ("B");
threadPriority t3 = new threadPriority ("C");
t1.setPriority (Thread.MIN_PRIORITY);
t2.setPriority (Thread.NORM_PRIORITY);
t3.setPriority (Thread.MAX_PRIORITY);
t1.start ();
t2.start ();
t3.start ();
}
}