-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadmethodsDemo.java
More file actions
29 lines (24 loc) · 853 Bytes
/
Copy pathThreadmethodsDemo.java
File metadata and controls
29 lines (24 loc) · 853 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
// ThreadMethodsDemo.java
// Program to demonstrate common thread methods
class MyThreadMethod extends Thread {
public void run() {
System.out.println(Thread.currentThread().getName() + " is running...");
}
}
public class ThreadMethodsDemo {
public static void main(String[] args) {
MyThreadMethod t1 = new MyThreadMethod();
MyThreadMethod t2 = new MyThreadMethod();
t1.setName("Thread-1");
t2.setName("Thread-2");
t1.start();
try {
t1.join(); // waits for t1 to finish before starting t2
} catch (InterruptedException e) {
System.out.println(e);
}
t2.start();
System.out.println("Priority of t1: " + t1.getPriority());
System.out.println("Priority of t2: " + t2.getPriority());
}
}