-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path13.java
More file actions
42 lines (37 loc) · 836 Bytes
/
13.java
File metadata and controls
42 lines (37 loc) · 836 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
36
37
38
39
40
41
42
class Th implements Runnable {
Thread thread;
String tn;
int pri;
Th(String s, int i) {
tn = s;
pri = i;
}
public void run() {
try {
for (int i = 0; i < 5; i++) {
System.out.println(thread.getName() + ", " + thread.getPriority() + ", " + i);
Thread.sleep(50);
}
} catch (InterruptedException e) {
System.out.println("Exception in thread: " + tn);
}
System.out.println("Thread " + tn);
}
public void start() {
if (thread == null) {
thread = new Thread(this, tn);
thread.setPriority(pri);
thread.setName(tn);
System.out.println("Start method " + thread.getName());
thread.start();
}
}
}
public class Main {
public static void main(String args[]) {
Th thread1 = new Th("First Thread", 4);
thread1.start();
Th thread2 = new Th("Second Thread", 6);
thread2.start();
}
}