package com.megatim.fdxconsultation.core.impl.dataproductionworker;
|
|
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
/**
|
*
|
* @author Gabuntu
|
*/
|
class DataProductionWorker extends Thread {
|
|
private final BlockingQueue<DataProductionTask> tasks = new LinkedBlockingQueue<>();
|
private volatile boolean running = true;
|
|
public DataProductionWorker(String name) {
|
super(name);
|
}
|
|
@Override
|
public void run() {
|
while (running) {
|
try {
|
DataProductionTask task = tasks.take();
|
task.processProduction();
|
} catch (InterruptedException ex) {
|
if (!running) {
|
break; // Exit if interrupted and not running
|
}
|
}
|
}
|
}
|
|
public void shutdown() {
|
running = false;
|
this.interrupt(); // Interrupt the thread to wake it up
|
}
|
|
public void addTask(DataProductionTask dataProductionTask) {
|
tasks.add(dataProductionTask);
|
}
|
|
}
|