GUI インターフェイスでコードを実行しようとしています。しかし、メインの方法に進む前に、GUI ウィンドウをすべて閉じる必要があります (必要な情報の一部は GUI ウィンドウから収集され、その情報がないと残りのコードを実行できません)。そこで、CountDownLatch を使用して 2 つのスレッドを作成することにしました (そのうちの 1 つはメイン メソッドで、もう 1 つは GUI を処理するクラスです)。しかし、コードを実行すると、GUI の最後で動かなくなり、コードが先に進みません。誰かが私のコードの何が問題なのか知っていますか?
public static void main (String[] args) throws IOException,InterruptedException{
long start = System.currentTimeMillis();
double longThreshold, shortThreshold, investment;
System.out.println("hello");
CountDownLatch startSignal = new CountDownLatch(1);
CountDownLatch stopSignal = new CountDownLatch(1);
ProgrammeSettings mySettings=new ProgrammeSettings(startSignal,stopSignal);
new Thread(mySettings).start(); // mysettings object is the GUI stuff
startSignal.countDown();
stopSignal.await();
longThreshold = mySettings.getlowerThreshold();
shortThreshold = mySettings.getupperThreshold();
investment =mySettings.getinvestment();
System.out.println("hello");
}
また、GUI の CountDownLatch のコードは次のとおりです。
public class ProgrammeSettings implements Runnable {
private final CountDownLatch startSignal;
private final CountDownLatch stopSignal;
ProgrammeSettings(CountDownLatch startSignal, CountDownLatch doneSignal) {
this.startSignal = startSignal;
this.stopSignal = doneSignal;
}
public void graphicDesign(){
// do some GUI stuff
}
@Override
public void run() {
// TODO Auto-generated method stub
try{
startSignal.await();
graphicDesign();
stopSignal.countDown();
}
catch( InterruptedException e){
}
}
}