int i=0; while(true){ // Create a job JPPFJob job = runner.createJob(args[0], i); // execute a blocking job runner.executeBlockingJob(job); i++; } }
public JPPFJob createJob(String args, int i) throws Exception { // create a JPPF job JPPFJob job = new JPPFJob(); // give this job a readable unique id that we can use to monitor and manage it. job.setName("Template Job Id :"+i); // for(int i=0; i<10; i++){ // add a task to the job. job.addTask(new JPPFTask(args)); // } // add more tasks here ... // there is no guarantee on the order of execution of the tasks, // however the results are guaranteed to be returned in the same order as the tasks. return job; }
public void executeBlockingJob(final JPPFJob job) throws Exception { // set the job in blocking mode. job.setBlocking(true); // Submit the job and wait until the results are returned. // The results are returned as a list of JPPFTask instances, // in the same order as the one in which the tasks where initially added the job. List<JPPFTask> results = jppfClient.submit(job); // process the results for (JPPFTask task: results) { // if the task execution resulted in an exception if (task.getException() != null) { System.out.println(task.getException().getMessage()); } else { System.out.println(task.getResult()); } } }
int i=0;while(true) { // Create a job JPPFJob job = runner.createJob(args[0], i); // configure the job as non-blocking job.setBlocking(false); JPPFResultCollector collector = new JPPFResultCollector(job); job.setResultListener(collector); // submit the job. For a non-blocking job, this method returns null immediatly // the results can be obtained later using the JPPFResultCollector jppfClient.submit(job); i++;}
public void run() { // write your task code here. System.out.println("Hello, this is the node executing a template JPPF task"); try{ Thread.sleep(6000); }catch(Exception ex){ } // ... // eventually set the execution results setResult("the execution was performed successfully"); }
public static void main(final String...args) { try { // create the JPPFClient. This constructor call causes JPPF to read the configuration file // and connect with one or multiple JPPF drivers. jppfClient = new JPPFClient(); // create a runner instance. TemplateApplicationRunner runner = new TemplateApplicationRunner(); long i =0; while(i<100){ // Create a job JPPFJob job = runner.createJob(i); // execute a blocking job // runner.executeBlockingJob(job); // execute a non-blocking job runner.executeNonBlockingJob(job); i++; } } catch(Exception e) { e.printStackTrace(); } finally { if (jppfClient != null) jppfClient.close(); } }