Commit | Line | Data |
---|---|---|
7e42d822 JB |
1 | class Main { |
2 | ||
3 | public static void main(String[] args) { | |
4 | final int THREADS_NUMBER = 3; | |
5 | ExThread threadArray[] = new ExThread[THREADS_NUMBER]; | |
6 | Thread t[] = new Thread[THREADS_NUMBER]; | |
7 | ||
8 | for (int i = 0; i < threadArray.length; i++) { | |
9 | threadArray[i] = new ExThread(String.valueOf(i)); | |
10 | t[i] = new Thread(threadArray[i]); | |
11 | t[i].start(); | |
12 | } | |
13 | ||
14 | for (int i = 0; i < threadArray.length; i++) { | |
15 | try { | |
16 | t[i].join(); | |
17 | } | |
18 | catch (InterruptedException e) { | |
19 | // this part is executed when an exception (in this example InterruptedException) occurs | |
20 | } | |
21 | } | |
22 | System.out.println("Threads execution finished"); | |
23 | } | |
24 | ||
25 | } |