Debian Codegraph @

current/template/ThreadPoolJob.java

raw symbols SCIP
1 package template;
2
3 import java.util.concurrent.ArrayBlockingQueue;
4
5 import shared.KillSwitch;
6
7 /**
8 *
9 * @author Brian Bushnell
10 * @date August 26, 2019
11 *
12 */
13 public class ThreadPoolJob<X, Y> {
14
15 public ThreadPoolJob(X x_, ArrayBlockingQueue<X> dest_){
16 x=x_;
17 dest=dest_;
18 }
19
20 /** Process a job */
21 final void doJob(){
22 result=doWork();
23 cleanup();
24 }
25
26 /** Do whatever specific work needs to be done for this job */
27 public Y doWork(){
28 KillSwitch.kill("Unimplemented Method");
29 return null;
30 }
31
32 /** Retire the job to the destination queue */
33 final void cleanup(){
34 boolean success=false;
35 while(!success) {
36 try {
37 dest.put(x);
38 success=true;
39 } catch (InterruptedException e) {
40 // TODO Auto-generated catch block
41 e.printStackTrace();
42 }
43 }
44 }
45
46 final boolean isPoison(){return x==null;}
47
48 public final X x;
49 final ArrayBlockingQueue<X> dest;
50 public Y result;
51
52 }