-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultithread7104prog8.java
47 lines (40 loc) · 1.14 KB
/
Multithread7104prog8.java
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
class prog8 {
/*
* Topic = Multithread
* prog.no 8 Create the program to create multiple threads by using Runnbale
* interface
*/
public static void main(String[] args) throws java.lang.ClassNotFoundException {
Runnable r1 = new MyRun("This is Thread 1");
Runnable r2 = new MyRun("This isThread 2");
Runnable r3 = new MyRun("This isThread 3");
Thread t1 = new Thread(r1);
Thread t2 = new Thread(r2);
Thread t3 = new Thread(r3);
t1.start();
t2.start();
t3.start();
}
@Override
public String toString() {
return "prog1 []";
}
}
class MyRun implements Runnable {
private String tn;
public MyRun(String name) {
this.tn = name;
}
@Override
public void run() {
for (int i = 1; i <= 5; i++) {
System.out.println(tn + " - Count is start: " + i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
System.out.println(tn + " now running has finished.");
}
}