JPPFJob job = ...;// tasks cannot be resubmittedjob.getSLA().setMaxTaskResubmits(0);// resubmits due to node errors are also countedjob.getSLA().setApplyMaxResubmitsUponNodeError(true);// ... submit the job and get the results ...
public class MyTask extends AbstractTask<String> { // will be set to true only if the task completes // and is sent back to the client without problem private boolean completed = false; public void run() { try { // ... update the DB ... this.completed = true; // last statement } catch (Exception e) { setThrowable(e); } } public boolean isCompleted() { return this.completed; }}
JPPFClient client = new JPPFClient();JPPFJob job = new JPPFJob();// ... other job settings ...job.add(new MyTask());List<Task<?>> results = client.submitJob(job);for (Task<?> task: results) { MyTask myTask = (MyTask) task; if (!myTask.isCompleted()) { // process task with potential issue }}
public class MyTask extends AbstractTask<Object> { private boolean taskCompleted = false; @Override public void run() { try { // get data from file, url, etc... fetchData(); // query the DB for possible duplicates if (!checkDatabaseUpdated()) { // if no duplicate, update the DB updateDatabase(); } else { ... } } finally { taskCompleted = true; } } private boolean checkDatabaseUpdated() { ... } public boolean isTaskCompleted() { return taskCompleted; }}
JPPFClient client = new JPPFClient();JPPFJob job = new JPPFJob();// add the initial tasks...boolean done = false;List<Task<?>> tasksToResubmit = new ArrayList<>();while (!done) { List<Task<?>> results = client.submitJob(job); for (Task<?> result: results) { MyTask task = (MyTask) result; if (!task.isTaskCompleted()) { // task did not complete tasksToResubmit.add(task); } else { // process the result ... } } if (tasksToResubmit.isEmpty()) { // job is done fully done = true; } else { job = new JPPFJob(); for (Task<?> task: tasksToResubmit) { job.add(task); tasksToResubmit.clear(); } }}
try { int nbTasks = 5;; long taskSleepTime = 2; JobDetails jobDetails = null; jppfClient = new JPPFClient(); Service service = Service.getInstance(); // Create a job with the specified number of tasks JPPFJob job = new JPPFJob(); job.setName("CompanyName"); job.getSLA().setMaxTaskResubmits(0); job.getSLA().setApplyMaxResubmitsUponNodeError(true); for (int i=1; i<=nbTasks; i++) { MyJppfTask task = new MyJppfTask(jobDetails); task.setId("" + i); job.add(task); } job.setBlocking(false);jppfClient.submitJob(job); output("MyTaskRunner ended"); } catch(Exception e) { e.printStackTrace(); } finally { if (jppfClient != null) jppfClient.close(); }