导致 dorun.run() 在 awt 事件指派线程上同步执行。在所有挂起的 awt 事件被处理完(然后)返回 dorun.run() 之前,此调用将处于阻塞状态。此方法应该在应用程序线程需要更新该 gui 时使用。而不应该从 eventdispatchthread 中调用此方法。下面是一个创建新应用程序线程的示例,该应用线程使用 invokeandwait 从事件指派线程输出一个字符串,完成后再从应用程序线程输出一个字符串。
final runnable dohelloworld = new runnable() {
public void run() {
system.out.println("hello world on " + thread.currentthread());
}
};
thread appthread = new thread() {
public void run() {
try {
swingutilities.invokeandwait(dohelloworld);
}
catch (exception e) {
e.printstacktrace();
}
system.out.println("finished on " + thread.currentthread());
}
};
appthread.start();
注意,如果 异常(在事件指派线程上),则它将被作为一个
有关此方法的更多文档和示例,请参阅 use threads 一节。
从 1.3 版本开始,此方法只覆盖了 java.awt.eventqueue.invokeandwait()。
抛出:interruptedexception - 如果等待事件指派线程执完成执行 dorun.run() 时被中断
invocationtargetexception - 如果在运行 dorun 时抛出异常另请参见: