EventQueue.java 文件源码

java
阅读 39 收藏 0 点赞 0 评论 0

项目:jvm-stm 作者:
/**
 * Causes runnable to have its run method called in the dispatch thread of the
 * EventQueue. This will happen after all pending events are processed. The
 * call blocks until this has happened. This method will throw an Error if
 * called from the event dispatcher thread.
 *
 * @exception InterruptedException If another thread has interrupted
 * this thread.
 * @exception InvocationTargetException If an exception is thrown when running
 * runnable.
 *
 * @since 1.2
 */
public static void invokeAndWait(Runnable runnable)
  throws InterruptedException, InvocationTargetException
{
  if (isDispatchThread ())
    throw new Error("Can't call invokeAndWait from event dispatch thread");

  EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); 
  Object notifyObject = new Object();

  InvocationEvent ie =
    new InvocationEvent(eq, runnable, notifyObject, true);

  synchronized (notifyObject)
    {
      eq.postEvent(ie);
      notifyObject.wait();
    }

  Exception exception;

  if ((exception = ie.getException()) != null)
    throw new InvocationTargetException(exception);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号