-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSample.java
More file actions
40 lines (36 loc) · 1 KB
/
Sample.java
File metadata and controls
40 lines (36 loc) · 1 KB
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
class MyThread extends Thread{
public MyThread(String name){
super(name);
start();
}
public void run(){
for(int i=0;i<5;i++){
System.out.println(Thread.currentThread().getName()+":"+i);
try{
Thread.sleep(1000);
}catch(InterruptedException e){
e.printStackTrace();
}
}
}
}
public class Sample {
public static void main(String[] args){
System.out.println("Main thread Started");
MyThread myThread= new MyThread("Child class");
for(int i=0;i<5;i++){
System.out.println(Thread.currentThread().getName()+":"+i);
try{
Thread.sleep(1000);
}catch(InterruptedException e){
e.printStackTrace();
}
}
try{
myThread.join();
}catch(InterruptedException e){
e.printStackTrace();
}
System.out.println("Main Thread Ended");
}
}