-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDaemonUser.java
More file actions
44 lines (35 loc) · 896 Bytes
/
DaemonUser.java
File metadata and controls
44 lines (35 loc) · 896 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
43
44
public class DaemonUser {
public static void main(String[] args) {
Thread daemon=new Thread(new Daemon());
Thread user=new Thread(new User());
daemon.setDaemon(true);
daemon.start();
user.start();
}
}
class Daemon implements Runnable{
@Override
public void run(){
int count=0;
while(count<500){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
count++;
System.out.println("Daemon running..");
}
}
}
class User implements Runnable{
@Override
public void run(){
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
System.out.println("User thread done");
}
}