-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractice13_MultiThreading.java
More file actions
45 lines (41 loc) · 1 KB
/
Practice13_MultiThreading.java
File metadata and controls
45 lines (41 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
package com.company;
//1.
class MyThread extends Thread {
public void run() {
while (true) {
// 2.
try {
Thread.sleep(200);
}
catch (Exception e) {
System.out.println(e);
}
System.out.println("Welcome");
}
}
}
class MyThread2 extends Thread {
public void run() {
while (true) {
System.out.println("Good Morning");
}
}
}
public class Practice13_MultiThreading {
public static void main(String[] args) {
MyThread p = new MyThread();
MyThread2 p2 = new MyThread2();
// 3.
p.setPriority(7);
p2.setPriority(8);
System.out.println(p.getPriority());
System.out.println(p2.getPriority());
// 4.
p.start();
p2.start();
System.out.println(p.getState());
System.out.println(p2.getState());
// 5.
System.out.println(Thread.currentThread().getState());
}
}