-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathMyThread.java
More file actions
38 lines (34 loc) · 1006 Bytes
/
MyThread.java
File metadata and controls
38 lines (34 loc) · 1006 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
37
38
package src.uni.lessons.multithreading;
public class MyThread implements Runnable {
Thread t;
public MyThread(String threadName) {
t = new Thread(this, threadName);
}
@Override
public void run() {
for (int i = 5; i >= 0; i--) {
try {
Thread.sleep(500);
System.out.println(i);
} catch (InterruptedException e) {
System.out.println("MyThread interrupted");
}
}
System.out.println("exiting MyThread...");
}
}
class MyTheadMain {
public static void main(String[] args) {
MyThread mt = new MyThread("My Thread");
mt.t.start();
try {
for (int i = 5; i >= 0; i--) {
System.out.println(i);
Thread.sleep(1000);
}
} catch (InterruptedException e) {
System.out.println("Main thread interrupted");
}
System.out.println("Exiting main thread...");
}
}