Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7007291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:35:17+00:00 2026-05-27T21:35:17+00:00

This method notifes an event loop to start processing a message. However, if the

  • 0

This method notifes an event loop to start processing a message. However, if the event loop is already processing a message then, this method blocks until it receives a notification of completed event processing (which is triggered at the end of the event loop).

public void processEvent(EventMessage request) throws Exception {
    System.out.println("processEvent");

    if (processingEvent) {
        synchronized (eventCompleted) {
            System.out.println("processEvent: Wait for Event to completed");
            eventCompleted.wait();
            System.out.println("processEvent: Event completed");
        }
    }

    myRequest = request;
    processingEvent = true;
    synchronized (eventReady) {
        eventReady.notifyAll();
    }
}

This works in client mode. If I switch to server mode and the time spent in the event loop processing the message is too quick, then the method above blocks forever waiting for the event to completed. For some reason the event complete notification is sent after the processingEvent check and before the eventCompleted.wait(). It makes no difference if I remove the output statements. I can not repeat the same problem in client mode.

Why does this only happen in server mode and what can I do to prevent this happening?

Here is the eventReady wait and eventCompleted notification:

public void run() {
    try {
        while (true) {
            try {
                synchronized (eventReady) {
                    eventReady.wait();
                }
                nx.processEvent(myRequest, myResultSet);
                if (processingEvent > 0) {
                    notifyInterface.notifyEventComplete(myRequest);
                }
            } catch (InterruptedException e) {
                throw e;
            } catch (Exception e) {
                notifyInterface.notifyException(e, myRequest);
            } finally {
                processingEvent--;
                synchronized (eventCompleted) {
                    eventCompleted.notifyAll();
                }
            }
        } // End of while loop
    } catch (InterruptedException Ignore) {
    } finally {
        me = null;
    }

Here is revised code which seems to work without the deadlock problem – which BTW happened in client mode randomely after about 300 events.

private BlockingQueue<EventMessage> queue = new SynchronousQueue<EventMessage>();

public void processEvent(EventMessage request) throws Exception {
    System.out.println("processEvent");

    queue.put(request);
}


public void run() {
    try {
        while (true) {
            EventMessage request = null;
            try {
                request = queue.take();
                processingEvent = true;
                nx.processEvent(request, myResultSet);
                notifyInterface.notifyEventComplete(request);
            } catch (InterruptedException e) {
                throw e;
            } catch (Exception e) {
                notifyInterface.notifyException(e, request);
            } finally {
                if (processingEvent) {
                    synchronized (eventCompleted) {
                        processingEvent = false;
                        eventCompleted.notifyAll();
                    }
                }
            }
        } // End of while loop
    } catch (InterruptedException Ignore) {
    } finally {
        me = null;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:35:17+00:00Added an answer on May 27, 2026 at 9:35 pm

    There are a number of race conditions in your code. Even declaring processingEvent volatile or using an AtomicBoolean won’t help. I would recommend using a SynchronousQueue which will block the event until the processer is ready for it. Something like:

    private final BlockingQueue<Request> queue = new SynchronousQueue<Request>();
    ...
    
    // this will block until the processor dequeues it
    queue.put(request);
    

    Then the event processor does:

    while (!done) {
       // this will block until an event is put-ed to the queue
       Request request = queue.take();
       process the event ...
    }
    

    Only one request will be processed at once and all of the synchronization, etc. will be handled by the SynchronousQueue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This method works as expected - it creates a JTree with a root node
With this method declaration (no overloads): void Method(double d) { // do something with
Take this method /** * @return List of group IDs the person belongs to
Can this method work? public String sayHello(){ return Hello.jsp?name= + laala; } I am
I have this method on a webpart: private IFilterData _filterData = null; [ConnectionConsumer(Filter Data
Every time I call this method my NSMutableData is leaking and I cannot figure
Having recently discovered this method of development, I'm finding it a rather nice methodology.
Should I be using this method of throwing errors: if (isset($this->dbfields[$var])) { return $this->dbfields[$var];
Currently i have this method: static boolean checkDecimalPlaces(double d, int decimalPlaces){ if (d==0) return
I have this method in my db class public function query($queryString) { if (!$this->_connected)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.