-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractical_35.java
More file actions
52 lines (48 loc) · 1.29 KB
/
Practical_35.java
File metadata and controls
52 lines (48 loc) · 1.29 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
/* Question := 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() {
while (true) {
try {
sleep(1000);
System.out.println("Hello");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
class WorldThread extends Thread {
public void run() {
while (true) {
try {
sleep(3000);
System.out.println("World");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public class Practical_35 {
public static void main(String[] args) {
HelloThread helloThread = new HelloThread();
WorldThread worldThread = new WorldThread();
helloThread.start();
worldThread.start();
}
}
/* Output :=
Hello
Hello
World
Hello
Hello
Hello
World
Hello
Hello
Hello
World
//upto infinity..
*/