-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainThread.java
More file actions
51 lines (29 loc) · 1.39 KB
/
MainThread.java
File metadata and controls
51 lines (29 loc) · 1.39 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
package threadclass;
public class MainThread {
public static void main(String[] args) {
FirstTask firstTask1 = new FirstTask();
FirstTask firstTask2 = new FirstTask();
FirstTask firstTask3 = new FirstTask();
SecondTask secondTask1 = new SecondTask();
SecondTask secondTask2 = new SecondTask();
SecondTask secondTask3 = new SecondTask();
ThirdTask thirdTask1 = new ThirdTask();
ThirdTask thirdTask2 = new ThirdTask();
ThirdTask thirdTask3 = new ThirdTask();
// Direct call to the run method will not create a new thread, it will execute in the main thread.
// .run() will execute the code in the current thread (main thread) and will not create a new thread of execution.
// .run method me call karne se new thread create nahi hota, ye code ko current thread (main thread) me execute karega.
// .start() method will create a new thread and execute the run method in that new thread.
// .start() method new thread create karega aur run method ko us new thread me execute karega.
firstTask1.start();
firstTask2.start();
firstTask3.start();
secondTask1.start();
secondTask2.start();
secondTask3.start();
thirdTask1.start();
thirdTask2.start();
thirdTask3.start();
//
}
}