-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
49 lines (39 loc) · 1.08 KB
/
Main.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
class MultiThreading extends Thread{
private int threadNumber;
MultiThreading(int threadNumber){
this.threadNumber=threadNumber;
}
public void run(){
for(int i=0;i<=5;i++){
System.out.println(i+" Thread "+threadNumber);
if(threadNumber==1)
throw new RuntimeException();
try{
Thread.sleep(1000);
}catch(InterruptedException e){
}
}
}
}
class ThreadingWithRunnable implements Runnable{
public void run(){
for(int i=5;i<=10;i++){
System.out.println(i);
try{
Thread.sleep(1000);
}catch(InterruptedException e){
}
}
}
}
public class Main{
public static void main(String[] args) {
for(int i=0;i<3;i++){
MultiThreading m = new MultiThreading(i);
m.start();
ThreadingWithRunnable tr = new ThreadingWithRunnable();
Thread t = new Thread(tr);
t.start();
}
}
}