1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.gwe.persistence.model.order;
18
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.concurrent.Callable;
22 import java.util.concurrent.ExecutionException;
23 import java.util.concurrent.ExecutorService;
24 import java.util.concurrent.Future;
25
26 import org.gwe.persistence.model.live.JobLive;
27 import org.gwe.utils.concurrent.ThreadPoolUtils;
28
29
30
31
32
33 public abstract class JobSideWorker extends ArrayList<Callable<Void>> {
34
35 private static ExecutorService threadPool = ThreadPoolUtils.createThreadPool("Job Side Workers");
36
37 public final void execute(JobLive ctx) throws Throwable {
38 beforeExecuteProcessors(ctx);
39 if (!this.isEmpty()) {
40 List<Future<Void>> results = threadPool.invokeAll(this);
41 for (Future<Void> result : results) {
42 try {
43 result.get();
44 } catch(ExecutionException e) {
45 throw e.getCause();
46 }
47 }
48 }
49 }
50
51 protected abstract void beforeExecuteProcessors(JobLive ctx) throws Exception;
52
53 }