-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultithreading1.java
More file actions
54 lines (40 loc) · 1.58 KB
/
multithreading1.java
File metadata and controls
54 lines (40 loc) · 1.58 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
51
52
53
54
//multithreading by extending thread
//
class thread1 extends Thread { // threading me run hone ke liye ,,, class ko Thread class se extends hona padta
// hai
public void run() {
while (true) {
System.out.println("thread 1 is running");
System.out.println("i am happy");
}
}
}
class thread2 extends Thread {
public void run() {
while (true) {
System.out.println("thread 2 is running");
System.out.println("i am sad");
}
}
}
public class multithreading1 {
public static void main(String[] args) {
// fun1(); //ye function suppose thread me run ho rahi hai
// fun2(); //ye bhi function thread me run ho rha hai
// aur yha bakika code likha hua hai
// to yaha pr fun1 & fun2 sab kuch ek sath run honge '//aur baki ka code bhi
// simultanaously run hota hai'
thread1 t1 = new thread1();
thread2 t2 = new thread2();
t1.start(); /// Thread class ko run karne ke lite object ko .start() method se run krna
/// padta hai
t2.start();
// yaha par dono method eksath run honge ..
// isme Thread class kuchh time thread1 ko deta hai
// aut Thread class kuchha time thread2 ko deta hai ...
// aur dono ek time pr execute hote hai
// par simultaneously nahi hote ,,, ek time pr ek method run hota hai ...
// par attend dono hote hai ...au
// aur execution faster hota hai
}
}