-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHundredThreads.java
More file actions
46 lines (37 loc) · 950 Bytes
/
HundredThreads.java
File metadata and controls
46 lines (37 loc) · 950 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
45
46
class MyThread extends Thread{
public MyThread(int id){
this.setName("Thread -d: "+id);
}
@Override
public void run(){
System.out.println(this.getName()+" is running!");
try {
Thread.sleep(10000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
// finally{
//
// }
System.out.println(this.getName() + " has completed execution.");
}
}
public class HundredThreads {
public static void main(String[] args) {
for(int i=0;i<100;i++){
MyThread t = new MyThread(i);
t.setDaemon(true);
t.start();
}
try {
Thread.sleep(10000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
finally{
System.out.println("Main Execution completed!");
}
}
}