-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractical35.java
More file actions
36 lines (33 loc) · 1001 Bytes
/
practical35.java
File metadata and controls
36 lines (33 loc) · 1001 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
36
// Write an Application that executes two threads. One displays “Hello” at every 1000 millisec. & Second displays “World” at every 3000 milliseconds. Create the threads by extending the Thread class.
class HelloThread extends Thread {
public void run() {
try {
while (true) {
System.out.println("Hello");
Thread.sleep(1000);
}
} catch (InterruptedException e) {
System.out.println(e);
}
}
}
class WorldThread extends Thread {
public void run() {
try {
while (true) {
System.out.println("World");
Thread.sleep(3000);
}
} catch (InterruptedException e) {
System.out.println(e);
}
}
}
public class practical35 {
public static void main(String[] args) {
HelloThread t1 = new HelloThread();
WorldThread t2 = new WorldThread();
t1.start();
t2.start();
}
}