-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreads.java
More file actions
32 lines (30 loc) · 957 Bytes
/
threads.java
File metadata and controls
32 lines (30 loc) · 957 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
/* Write a java program that implements Thread class methods */
package Thread;
class threads extends Thread{
public void run(){
for(int i = 1; i <= 5; i++){
try{
System.out.println("running thread name is: " + Thread.currentThread().getName());
System.out.println("running thread priority is:" + Thread.currentThread().getPriority());
}catch (Exception e){
System.out.println(e);
}
System.out.println(i);
}
}
public static void main(String args[]) {
threads t0 = new threads();
threads t1 = new threads();
threads t2 = new threads();
t1.setPriority(Thread.MAX_PRIORITY);
t2.setPriority(Thread.MIN_PRIORITY);
t0.start();
try {
t0.join();
} catch (Exception e) {
System.out.println(e);
}
t1.start();
t2.start();
}
}