1 | |
package org.kuali.maven.wagon; |
2 | |
|
3 | |
import java.lang.Thread.UncaughtExceptionHandler; |
4 | |
|
5 | 0 | public class ThreadHandler implements UncaughtExceptionHandler { |
6 | |
|
7 | |
ThreadGroup group; |
8 | |
Thread[] threads; |
9 | |
Throwable exception; |
10 | 0 | boolean stopThreads = false; |
11 | |
|
12 | |
public ThreadGroup getGroup() { |
13 | 0 | return group; |
14 | |
} |
15 | |
|
16 | |
public void setGroup(ThreadGroup group) { |
17 | 0 | this.group = group; |
18 | 0 | } |
19 | |
|
20 | |
public Thread[] getThreads() { |
21 | 0 | return threads; |
22 | |
} |
23 | |
|
24 | |
public void setThreads(Thread[] threads) { |
25 | 0 | this.threads = threads; |
26 | 0 | } |
27 | |
|
28 | |
public void executeThreads() { |
29 | 0 | start(); |
30 | 0 | join(); |
31 | 0 | } |
32 | |
|
33 | |
protected void start() { |
34 | 0 | for (Thread thread : threads) { |
35 | 0 | thread.start(); |
36 | |
} |
37 | 0 | } |
38 | |
|
39 | |
protected void join() { |
40 | |
try { |
41 | 0 | for (Thread thread : threads) { |
42 | 0 | thread.join(); |
43 | |
} |
44 | 0 | } catch (InterruptedException e) { |
45 | 0 | throw new RuntimeException(e); |
46 | 0 | } |
47 | 0 | } |
48 | |
|
49 | |
public void uncaughtException(Thread t, Throwable e) { |
50 | 0 | setStopThreads(true); |
51 | 0 | setException(new RuntimeException("Unexpected issue in thread [" + t.getId() + ":" + t.getName() + "]", e)); |
52 | 0 | } |
53 | |
|
54 | |
public Throwable getException() { |
55 | 0 | return exception; |
56 | |
} |
57 | |
|
58 | |
public void setException(Throwable exception) { |
59 | 0 | this.exception = exception; |
60 | 0 | } |
61 | |
|
62 | |
public synchronized boolean isStopThreads() { |
63 | 0 | return stopThreads; |
64 | |
} |
65 | |
|
66 | |
public synchronized void setStopThreads(boolean stopThreads) { |
67 | 0 | this.stopThreads = stopThreads; |
68 | 0 | } |
69 | |
|
70 | |
} |