在我的應用程序中,我有兩個jtextpanes,我有一個executorservice instacne包含幾個任務。我想確保在執行任何jtextpanes的FocusListener focusGained方法之前完成executorservice實例中的所有任務。當我調用focusLost方法時,我還向executorservice添加了一些更多的任務。阻止EDT直到executorservice完成所有任務
代碼
top.addFocusListener(new FocusListener()
{
public void focusLost(FocusEvent e)
{
if (ecaViewControl.isInitialized())
{
stopRecording();
executor.execute(new Runnable()
{
public void run()
{
ecaViewControl.save(top);
}
});
executor.execute(new Runnable()
{
public void run()
{
ecaViewControl.closeDocument();
}
});
}
}
public void focusGained(FocusEvent e)
{
//Need to have completed all the task in executor service before EDT executes the code in here
});
}
所以你想阻止用戶界面,直到所有任務完成?這是一個好主意嗎? – Tudor