-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultithreading.java
More file actions
50 lines (46 loc) · 1.23 KB
/
Copy pathMultithreading.java
File metadata and controls
50 lines (46 loc) · 1.23 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
41
42
43
44
45
46
47
48
49
50
package BASICS;
//Both thread will run concurrently
//i.e t1 will execute then t2 then again t1
class Mythread1 extends Thread{
public void run(){
int n = 100;
while(n-- != 0)
System.out.println("Harshit");
}
}
class Mythread2 extends Thread{
public void run(){
int n = 100;
while(n-- != 0)
System.out.println("Vanshika");
}
}
class MyThreadRun1 implements Runnable{
public void run(){
int n = 10;
while(n-- != 0)
System.out.println("Im Harshit Bansal");
}
}
class MyThreadRun2 implements Runnable{
final int n = 100;
public void run(){
int n = 10;
while(n-- != 0)
System.out.println(this.n);
}
}
public class Multithreading {
public static void main(String[] args) {
// Mythread1 t1 = new Mythread1();
// Mythread2 t2 = new Mythread2();
// t1.start();
// t2.start();
MyThreadRun1 bullet1 = new MyThreadRun1();
Thread gun1 = new Thread(bullet1);
MyThreadRun2 bullet2 = new MyThreadRun2();
Thread gun2 = new Thread(bullet2); // Runnable dont have a start function, thus we uses Thread to run them
gun1.start();
gun2.start();
}
}