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