-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab8_2.java
More file actions
30 lines (26 loc) · 763 Bytes
/
Lab8_2.java
File metadata and controls
30 lines (26 loc) · 763 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
class MyThread extends Thread {
private String threadName;
MyThread(String name) {
threadName = name;
}
public void run() {
for(int i = 0; i < 5; i++) {
System.out.println(threadName + " is running: " + i);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
System.out.println("Thread has been interrupted");
}
}
}
}
public class Lab8_2 {
public static void main(String[] args) {
MyThread thread1 = new MyThread("Thread 1");
MyThread thread2 = new MyThread("Thread 2");
MyThread thread3 = new MyThread("Thread 3");
thread1.start();
thread2.start();
thread3.start();
}
}