如何使用CounDownLatch
两个不同的线程,每个线程都有相同的可运行类?我希望 FICS 和 fiCS_R7 具有相同的可运行类 FICS,但是当 fiCS_R3 完成时 fiCS_R7 启动。
我怎样才能做到这一点。
代码:
public FICSFilter(Mat bgrMat, int csRadius) {
// TODO Auto-generated constructor stub
this.bgrMat = bgrMat;
this.csRadius = csRadius;
CountDownLatch latch = new CountDownLatch(1);
this.fiCS_R3 = new Thread(new FICS(this.bgrMat, 3), "FICS_R" + this.csRadius);
fiCS_R3.start();
this.fiCS_R3 = new Thread(new FICS(this.bgrMat, 7), "FICS_R" + this.csRadius);
fiCS_R7.start();
//How to use the CounDownLatch for two different threads each of them has the same runnable class
}
private class FICS implements Runnable {
private Mat bgrMat;
private int csRadius;
public FICS(Mat bgrMat, int csRadius) {
// TODO Auto-generated constructor stub
this.bgrMat = bgrMat;
this.csRadius = csRadius;
}
public void run() {
// TODO Auto-generated method stub
calcFICS(this.bgrMat, this.csRadius);
}
public static void calcFICS(Mat bgrMat, int csRadius) {
// TODO Auto-generated method stub
ArrayList<Mat> onOffCSActRegMatsList = null;
ArrayList<Mat> offOnCSActRegMatsList = null;
ArrayList<Mat> onOffCSFullMatsList = null;
ArrayList<Mat> offOnCSFullMatsList = null;
onOffCSActRegMatsList = new ArrayList<Mat>();
offOnCSActRegMatsList = new ArrayList<Mat>();