Example usage for java.lang Object notify

List of usage examples for java.lang Object notify

Introduction

In this page you can find the example usage for java.lang Object notify.

Prototype

@HotSpotIntrinsicCandidate
public final native void notify();

Source Link

Document

Wakes up a single thread that is waiting on this object's monitor.

Usage

From source file:Main.java

public static void notify(Object o) {
    o.notify();
}

From source file:Main.java

/**
 * Notifies an object for synchronization purposes.
 *//* w ww. j  ava2  s.  co m*/
public static void notify(Object obj) {
    synchronized (obj) {
        obj.notify();
    }
}

From source file:Main.java

public static void notify(Object o) {
    synchronized (o) {
        o.notify();
    }
}

From source file:Main.java

public static final void doNotify(Object obj) {
    synchronized (obj) {
        obj.notify();
    }//from  ww  w  . ja  v a 2 s.  com
}

From source file:org.eclipse.orion.internal.server.servlets.task.TaskJobHandler.java

/**
 * Schedules {@link TaskJob} and handles response. If job lasts more than {@link this#WAIT_TIME}
 * handler starts a task and returns 202 (Accepted) response with task details. If job finishes sooner the
 * response if immediately returned filled with {@link TaskJob#getResult()}, if result is OK, than only
 * {@link ServerStatus#getJsonData()} is returned, if result is OK and it is not an instance of {@link ServerStatus}
 * than {@link TaskJob#getFinalResult()} is returned as a response content.
 * /*  w ww.  j  a v a2  s. co  m*/
 * @param request
 * @param response
 * @param job Job that should be handled as a task.
 * @param statusHandler status handler to handle error statuses.
 * @return <code>true</code> if job was handled properly.
 * @throws IOException
 * @throws ServletException
 * @throws URISyntaxException
 * @throws JSONException
 */
public static boolean handleTaskJob(HttpServletRequest request, HttpServletResponse response, TaskJob job,
        ServletResourceHandler<IStatus> statusHandler)
        throws IOException, ServletException, URISyntaxException, JSONException {
    job.schedule();

    final Object jobIsDone = new Object();
    final JobChangeAdapter jobListener = new JobChangeAdapter() {
        public void done(IJobChangeEvent event) {
            synchronized (jobIsDone) {
                jobIsDone.notify();
            }
        }
    };
    job.addJobChangeListener(jobListener);

    try {
        synchronized (jobIsDone) {
            if (job.getState() != Job.NONE) {
                jobIsDone.wait(WAIT_TIME);
            }
        }
    } catch (InterruptedException e) {
    }
    job.removeJobChangeListener(jobListener);

    if (job.getState() == Job.NONE || job.getRealResult() != null) {
        return writeResult(request, response, job, statusHandler);
    } else {
        TaskInfo task = job.startTask();
        JSONObject result = task.toJSON();
        URI taskLocation = createTaskLocation(ServletResourceHandler.getURI(request), task.getId(),
                task.isKeep());
        result.put(ProtocolConstants.KEY_LOCATION, taskLocation);
        if (!task.isRunning()) {
            job.removeTask(); // Task is not used, we may remove it
            return writeResult(request, response, job, statusHandler);
        }
        response.setHeader(ProtocolConstants.HEADER_LOCATION,
                ServletResourceHandler.resovleOrionURI(request, taskLocation).toString());
        OrionServlet.writeJSONResponse(request, response, result);
        response.setStatus(HttpServletResponse.SC_ACCEPTED);
        return true;
    }
}

From source file:org.apache.struts2.interceptor.ScopeInterceptor.java

static void unlock(Object o) {
    synchronized (o) {
        locks.remove(o);
        o.notify();
    }
}

From source file:com.duker.mygift.struts.interceptor.ScopeInterceptor.java

static final void unlock(Object o) {
    synchronized (o) {
        locks.remove(o);
        o.notify();
    }
}

From source file:Main.java

public static void streamMidiSequence(URL url)
        throws IOException, InvalidMidiDataException, MidiUnavailableException {
    Sequencer sequencer = null; // Converts a Sequence to MIDI events
    Synthesizer synthesizer = null; // Plays notes in response to MIDI events

    try {/*from  w  ww.j a  v  a2  s . co m*/
        // Create, open, and connect a Sequencer and Synthesizer
        // They are closed in the finally block at the end of this method.
        sequencer = MidiSystem.getSequencer();
        sequencer.open();
        synthesizer = MidiSystem.getSynthesizer();
        synthesizer.open();
        sequencer.getTransmitter().setReceiver(synthesizer.getReceiver());

        // Specify the InputStream to stream the sequence from
        sequencer.setSequence(url.openStream());

        // This is an arbitrary object used with wait and notify to
        // prevent the method from returning before the music finishes
        final Object lock = new Object();

        // Register a listener to make the method exit when the stream is
        // done. See Object.wait() and Object.notify()
        sequencer.addMetaEventListener(new MetaEventListener() {
            public void meta(MetaMessage e) {
                if (e.getType() == END_OF_TRACK) {
                    synchronized (lock) {
                        lock.notify();
                    }
                }
            }
        });

        // Start playing the music
        sequencer.start();

        // Now block until the listener above notifies us that we're done.
        synchronized (lock) {
            while (sequencer.isRunning()) {
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                }
            }
        }
    } finally {
        // Always relinquish the sequencer, so others can use it.
        if (sequencer != null)
            sequencer.close();
        if (synthesizer != null)
            synthesizer.close();
    }
}

From source file:org.apache.struts2.interceptor.ScopeInterceptor.java

static void lock(Object o, ActionInvocation invocation) throws Exception {
    synchronized (o) {
        int count = 3;
        Object previous;/*from  w w  w  .  j  a  v a2  s  . c  o m*/
        while ((previous = locks.get(o)) != null) {
            if (previous == invocation) {
                return;
            }
            if (count-- <= 0) {
                locks.remove(o);
                o.notify();

                throw new StrutsException("Deadlock in session lock");
            }
            o.wait(10000);
        }
        locks.put(o, invocation);
    }
}

From source file:com.beetle.framework.util.OtherUtil.java

/**
 * ?sleep?object.wait//from www .  j a v a 2 s .c  om
 * 
 * @param lockObj
 *            ?
 * @param sometime
 *            ??
 * @throws InterruptedException
 */
public static final void blockSomeTime(final Object lockObj, long sometime) throws InterruptedException {
    if (Thread.interrupted())
        throw new InterruptedException();
    synchronized (lockObj) {
        long waitTime = sometime;
        long start = System.currentTimeMillis();
        try {
            for (;;) {
                lockObj.wait(waitTime);
                waitTime = sometime - (System.currentTimeMillis() - start);
                if (waitTime <= 0) {
                    break;
                }
            }
        } catch (InterruptedException ex) {
            lockObj.notify();
            throw ex;
        }
    }
}