-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadsWithName.java
More file actions
33 lines (26 loc) · 822 Bytes
/
ThreadsWithName.java
File metadata and controls
33 lines (26 loc) · 822 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
package mthread;
public class ThreadsWithName extends Thread {
@Override
public void run() {
System.out.println("run(): Thread Name: " + Thread.currentThread().getName());
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(
"Priority: " + Thread.currentThread().getPriority() + " IsDemon:" + Thread.currentThread().isDaemon());
}
public static void main(String[] args) {
ThreadsWithName t = new ThreadsWithName();
t.setPriority(Thread.MAX_PRIORITY);
t.setName("Thread1");
ThreadsWithName t2 = new ThreadsWithName();
t2.setName("Thread2");
t2.setPriority(4);
t2.setDaemon(true);
t.start();
t2.start();
System.out.println("main(): Thread Name: " + Thread.currentThread().getName());
}
}