Example usage for java.lang Thread notifyAll

List of usage examples for java.lang Thread notifyAll

Introduction

In this page you can find the example usage for java.lang Thread notifyAll.

Prototype

@HotSpotIntrinsicCandidate
public final native void notifyAll();

Source Link

Document

Wakes up all threads that are waiting on this object's monitor.

Usage

From source file:au.com.jwatmuff.eventmanager.util.GUIUtils.java

/**
 * Makes a frame visible and blocks the caller until the frame is closed.
 * //from  w ww.j a  va  2 s.c o m
 * @param frame
 */
public static void runModalJFrame(final JFrame frame) {
    // there may be a much better way of implementing this, i don't know..
    class RunningFlag {
        boolean value = true;
    }

    final RunningFlag flag = new RunningFlag();
    final Thread t = Thread.currentThread();

    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                frame.addWindowListener(new WindowAdapter() {
                    @Override
                    public void windowClosed(WindowEvent arg0) {
                        synchronized (t) {
                            flag.value = false;
                            t.notifyAll();
                        }
                    }
                });

                frame.setVisible(true);

            }
        });

        synchronized (t) {
            while (flag.value == true)
                try {
                    t.wait();
                } catch (InterruptedException e) {
                }
        }
    } catch (InterruptedException e) {
        log.error(e);
    } catch (InvocationTargetException e2) {
        log.error(e2);
    }
}