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 | |
boolean stopThreads; |
11 | |
int requestsPerThread; |
12 | |
int threadCount; |
13 | |
ProgressTracker tracker; |
14 | |
|
15 | |
public ThreadGroup getGroup() { |
16 | 0 | return group; |
17 | |
} |
18 | |
|
19 | |
public void setGroup(ThreadGroup group) { |
20 | 0 | this.group = group; |
21 | 0 | } |
22 | |
|
23 | |
public Thread[] getThreads() { |
24 | 0 | return threads; |
25 | |
} |
26 | |
|
27 | |
public void setThreads(Thread[] threads) { |
28 | 0 | this.threads = threads; |
29 | 0 | } |
30 | |
|
31 | |
public void executeThreads() { |
32 | 0 | start(); |
33 | 0 | join(); |
34 | 0 | } |
35 | |
|
36 | |
protected void start() { |
37 | 0 | for (Thread thread : threads) { |
38 | 0 | thread.start(); |
39 | |
} |
40 | 0 | } |
41 | |
|
42 | |
protected void join() { |
43 | |
try { |
44 | 0 | for (Thread thread : threads) { |
45 | 0 | thread.join(); |
46 | |
} |
47 | 0 | } catch (InterruptedException e) { |
48 | 0 | throw new RuntimeException(e); |
49 | 0 | } |
50 | 0 | } |
51 | |
|
52 | |
public synchronized void uncaughtException(Thread t, Throwable e) { |
53 | 0 | this.stopThreads = true; |
54 | 0 | this.exception = new RuntimeException("Unexpected issue in thread [" + t.getId() + ":" + t.getName() + "]", e); |
55 | 0 | } |
56 | |
|
57 | |
public Throwable getException() { |
58 | 0 | return exception; |
59 | |
} |
60 | |
|
61 | |
public synchronized boolean isStopThreads() { |
62 | 0 | return stopThreads; |
63 | |
} |
64 | |
|
65 | |
public int getRequestsPerThread() { |
66 | 0 | return requestsPerThread; |
67 | |
} |
68 | |
|
69 | |
public void setRequestsPerThread(int requestsPerThread) { |
70 | 0 | this.requestsPerThread = requestsPerThread; |
71 | 0 | } |
72 | |
|
73 | |
public int getThreadCount() { |
74 | 0 | return threadCount; |
75 | |
} |
76 | |
|
77 | |
public void setThreadCount(int threadCount) { |
78 | 0 | this.threadCount = threadCount; |
79 | 0 | } |
80 | |
|
81 | |
public ProgressTracker getTracker() { |
82 | 0 | return tracker; |
83 | |
} |
84 | |
|
85 | |
public void setTracker(ProgressTracker tracker) { |
86 | 0 | this.tracker = tracker; |
87 | 0 | } |
88 | |
} |