-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultithread.java
More file actions
37 lines (34 loc) · 1004 Bytes
/
multithread.java
File metadata and controls
37 lines (34 loc) · 1004 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
class Thread implements Runnable {
Thread t;
Thread M(){ //from here it will parallelly execute Thread M at same time
t=new Thread("demo thread");
System.out.println("thread details",t);
t.start();
}
public void run(){
try{
for(int i=0;i<5;i++){
System.out.println("child thread",t);
thread.sleep(500);
}
}
catch(InterruptedException e){
System.out.println(i);
}
}
}
public class multithread{
public static void main(String args[]){
new Thread ();
try{
for(int i=5;i<1;i--){
System.out.println("Main Thread");
thread.sleep(1000);
}
}
catch(Interpted Exception){
System.out.println("at end "+ i);
}
}
}
//output will be 2 execution of first for loop and 1 execultion of second for loop