-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiThreading.java
More file actions
35 lines (29 loc) · 811 Bytes
/
MultiThreading.java
File metadata and controls
35 lines (29 loc) · 811 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
// WAP to demonstarte the use of multithreading
class MyTask1 implements Runnable {
public void run() {
for(int i = 1; i <= 5; i++) {
System.out.println("Runnable Thread: " + i);
}
}
}
class MyTask2 implements Runnable {
public void run() {
for(int i = 1; i <= 5; i++) {
System.out.println("Runnable Thread: " + i);
try{
Thread.sleep(1000);
}
catch(Exception e){
System.out.println("Error: " + e.getMessage());
}
}
}
}
public class MultiThreading {
public static void main(String[] args) {
Thread t1 = new Thread(new MyTask1());
Thread t2 = new Thread(new MyTask2());
t1.start();
t2.start();
}
}