View Javadoc

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