so heres my code
theres a line that i am interested in
Code
while (!executor.isTerminated()) {
}
i use it to wait until everythings done before printing just wondering if theres a better way
Code
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* Created by user on 9/28/2016.
*/
public class Router {
public static void main(String[] args) {
Branch P = new Branch('P');
Branch F = new Branch('F');
Branch M = new Branch('M');
ExecutorService executor = Executors.newFixedThreadPool(9);
Job[] jobs = new Job[9];
jobs[0] = new Job(P, 1, 'D', 60000);
jobs[1] = new Job(P, 3, 'P', 100000);
jobs[2] = new Job(P, 2, 'D', 75000);
jobs[3] = new Job(F, 1, 'P', 30000);
jobs[4] = new Job(F, 2, 'D', 150000);
jobs[5] = new Job(F, 3, 'P', 89000);
jobs[6] = new Job(M, 1, 'P', 200000);
jobs[7] = new Job(M, 2, 'D', 140000);
jobs[8] = new Job(M, 3, 'P', 135000);
for (Job job : jobs) {
executor.execute(job);
}
executor.shutdown();
while (!executor.isTerminated()) {
}
F.printBranch();
P.printBranch();
M.printBranch();
}
}
edit: this is meant for a single processor system, it doesnt seem to be necessary when run on a multiprocessor system
This post was edited by Ideophobe on Sep 30 2016 02:02am