-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathExampleMultiThreads.java
51 lines (34 loc) · 946 Bytes
/
ExampleMultiThreads.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
48
49
50
51
class thread1 extends Thread{
public void run(){
try{
for (int i = 0; i <= 10; i++) {
System.out.println("Welcome to Thread 1 --- No. "+i);
Thread.sleep(1000);
}
}catch(Exception e){
System.err.println(e);
}
}
}
class thread2 extends Thread{
public void run(){
try{
for (int i = 0; i <= 10; i++) {
System.out.println("Welcome to Thread 2 ****** No. "+i);
Thread.sleep(1000);
}
}catch(Exception e){
System.err.println(e);
}
}
}
public class ExampleMultiThreads {
public static void main(String[] args) {
//Thread th = new Thread();
//th.start();
thread1 th1 = new thread1();
thread2 th2 = new thread2();
th1.start();
th2.start();
}
}