rendered paste bodyimport Supercomputer.*;
public class App {
public static void main(String[] args) {
SumUpJob superJob = new SumUpJob(SupercomputerJob.INITIALJOB, 1, 10);
SupercomputerJob[] jobs;
try {
jobs = superJob.partitionJob(5);
} catch (Exception e) {
e.printStackTrace();
return;
}
AppThread[] threads = new AppThread[jobs.length];
for (int i=0; i<threads.length; ++i) {
threads[i] = new AppThread(jobs[i]);
threads[i].start();
}
boolean running;
do {
running = false;
for (int i=0; i<threads.length; ++i) {
if (threads[i].isAlive()) {
running = true;
break;
}
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
} while (running);
Object[] results = new Object[jobs.length];
for (int i=0; i<threads.length; ++i) {
results[i] = threads[i].getResult();
}
superJob.mergeAndDisplayJobResults(results);
}
}
class AppThread extends Thread {
private SupercomputerJob job;
private Object[] result;
public AppThread(SupercomputerJob job) {
this.job = job;
}
public void run() {
result = job.doTask();
}
public Object[] getResult() {
return result;
}
}