public Message receiveMessage()
    {
        while ((m_stack != null) && (m_stack.isEmpty()))
        {
            m_thread = Thread.currentThread();
            synchronized(m_thread)
            {
                m_bWaiting = true;
                if (m_stack.isEmpty())      // In case a message was added outside the sync block.
                {
                    try {
                        m_thread.wait();
                    } catch (InterruptedException ex)   {
                        m_stack = null; // This causes a null message to return, which tells the receiving loop to stop (halting this thread).
                        m_thread = null;    // Don't free this twice.
                    }
                }
                m_bWaiting = false;     // Notified
            }
        }
        Message message = null;
        if (m_stack != null)
            if (!m_stack.isEmpty())
                message = m_stack.remove(0);
        return message;
    }
public Message receiveMessage ( ) { while ( ( m_stack != null ) && ( m_stack . isEmpty ( ) ) ) { m_thread = Thread . currentThread ( ) ; synchronized ( m_thread ) { m_bWaiting = true ; if ( m_stack . isEmpty ( ) ) { try { m_thread . wait ( ) ; } catch ( InterruptedException ex ) { m_stack = null ; m_thread = null ; } } m_bWaiting = false ; } } Message message = null ; if ( m_stack != null ) if ( ! m_stack . isEmpty ( ) ) message = m_stack . remove ( 0 ) ; return message ; }
Process the receive message call.
Note: Be careful, this call blocks until the message is ready to be received.
@return The next message (when it becomes available).