/* This is my Main thread */
ToolThread[] runThread = new ToolThread[3]
for (int i = 0; i < 3; i++) {
runThread[i] = new ToolThread(i);
runThread[i].start();
}
for (int j = 0;j<3;j++) {
try {
runThread[i].join();
}
catch (InterruptedException ex) {
}
}
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
apigee, a better way to API!
Ed's latest article: A Java Reactive Generator http://coopsoft.com/ar/ReactiveArticle.html
/* This is my Main thread */
CountDownLatch startSignal = new CountDownLatch(1);
CountDownLatch doneSignal = new CountDownLatch(3);
ToolThread[] runThread = new ToolThread[3]
for (int i = 0; i < 3; i++) {
runThread[i] = new ToolThread(i);
runThread[i].start();
startSignal.countDown(); // let all threads proceed
int return = runThread[i].getStatus();
if (return != 0) {//this means error
// forcing the latch count to zero
for (; doneSignal.getCount() > 0; doneSignal.countDown()){}
}
doneSignal.await(); // wait for all to finish
}
class ToolThread extends Thread {
private final CountDownLatch startSignal;
private final CountDownLatch doneSignal;
private int status;
ToolThread(CountDownLatch startSignal, CountDownLatch doneSignal) {
this.startSignal = startSignal;
this.doneSignal = doneSignal;
}
public int getStatus(){
return status;
}
public void run() {
try {
startSignal.await();
status = doWork();
doneSignal.countDown();
}
catch (InterruptedException ex) {}
}
}
Ed's latest article: A Java Reactive Generator http://coopsoft.com/ar/ReactiveArticle.html
"I'm not back." - Bill Harding, Twister
Ed's latest article: A Java Reactive Generator http://coopsoft.com/ar/ReactiveArticle.html
------------------------
Bob
SCJP - 86% - June 11, 2009
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
They weren't very bright, but they were very, very big. Ad contrast:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|