-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemoMainThread.java
More file actions
29 lines (26 loc) · 838 Bytes
/
DemoMainThread.java
File metadata and controls
29 lines (26 loc) · 838 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
class MyThread implements Runnable {
String message;
MyThread(String msg) {
message = msg;
}
public void run() {
for (int i = 0; i <= 5; i++) {
try {
System.out.println("Run method: " + message + " " + "count-" + i);
Thread.sleep(100);
} catch (InterruptedException ie) {
System.out.println("Exception in thread: " + ie.getMessage());
}
}
}
}
public class DemoMainThread {
public static void main(String[] args) {
MyThread obj1 = new MyThread("MyThread obj1");
MyThread obj2 = new MyThread("MyThread obj2");
Thread t1 = new Thread(obj1); // creating thread object t1 using Thread() constructor
Thread t2 = new Thread(obj2);
t1.start();
t2.start();
}
}