- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram29_MultiThreading.java
More file actions
Latest commit
34 lines (29 loc) · 1.03 KB
/
Copy pathProgram29_MultiThreading.java
File metadata and controls
34 lines (29 loc) · 1.03 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
// Write a java program to showcases how multithreading allows multiple tasks to be executed simultaneously by printing a count from 1 to 5 with a 1-second delay between each count
// Date : 20/03/2024, Author : Yash Wadhvani
classCountingThreadextendsThread {
privateintstart;
privateStringthreadName;
publicCountingThread(StringthreadName, intstart) {
this.threadName = threadName;
this.start = start;
}
@Override
publicvoidrun() {
for (inti = start; i <= start + 4; i++) {
System.out.println(threadName + "\tCount :" + i);
try {
Thread.sleep(1000);
} catch (InterruptedExceptione) {
e.printStackTrace();
}
}
}
}
publicclassProgram29_MultiThreading {
publicstaticvoidmain(String[] args) {
CountingThreadthread1 = newCountingThread("Thread A", 1);
CountingThreadthread2 = newCountingThread("Thread B", 6);
thread1.start();
thread2.start();
}
}