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 7552069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:39:58+00:00 2026-05-30T10:39:58+00:00

I have an app that needs to wait for some unknown amount of time.

  • 0

I have an app that needs to wait for some unknown amount of time. It must wait until several data fields are finished being populated by a server.

The server’s API provides me a way to request data, easy enough…

The server’s API also provides a way to receive my data back, one field at a time. It does not tell me when all of the fields are finished being populated.

What is the most efficient way to wait until my request is finished being processed by the server? Here’s some pseudocode:

public class ServerRequestMethods {
    public void requestData();
}

public interface ServerDeliveryMethods {
    public void receiveData(String field, int value);
}

public class MyApp extends ServerRequestMethods implements ServerDeliveryMethods {
    //store data fields and their respective values
    public Hashtable<String, Integer> myData;    

    //implement required ServerDeliveryMethods
    public void receiveData(String field, int value) {
        myData.put(field, value);    
    }

    public static void main(String[] args) {
        this.requestData();

        // Now I have to wait for all of the fields to be populated,
        // so that I can decide what to do next.

        decideWhatToDoNext();
        doIt();
    }
}

I have to wait until the server is finished populating my data fields, and the server doesn’t let me know when the request is complete. So I must keep checking whether or not my request has finished processing. What is the most efficient way to do this?

wait() and notify(), with a method guarding the while loop that checks if I have all of the required values yet every time I’m woken up by notify()?

Observer and Observable, with a method that checks if I have the all the required values yet every time my Observer.Update() is called?

What’s the best approach? Thanks.

  • 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-30T10:39:59+00:00Added an answer on May 30, 2026 at 10:39 am

    If I understood you right, some other thread calls receiveData on your MyApp to fill the data. If that’s right, then here’s how you do it:

    1. You sleep like this:

      do {
          this.wait(someSmallTime); //We are aquiring a monitor on "this" object, so it would require a notification. You should put some time (like 100msec maybe) to prevent very rare but still possible deadlock, when notification came before this.wait was called.
      } while (!allFieldsAreFilled());
      
    2. receiveData should make a notify call, to unpause that wait call of yours. For example like this:

      myData.put(field, value);   
      this.notify();
      
    3. Both blocks will need to be “synchronized” on this object to be able to aquire it’s monitor (that’s needed for wait). You need to either declare the methods as “synchronized”, or put the respective blocks inside synchronized(this) {...} block.

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

Sidebar

Related Questions

I have a MySQL/Rails app that needs search. Here's some info about the data:
I have a wpf app that needs to communicate(exchange data) with a custom designed
I have an app that has a bunch of Core Data that it needs
I have a Django app that needs to pull the follower_count information from several
I have android app that talks to server and syncs some data int SQLite
my app needs to download some data (about 50k) on launch time. I'm currently
I have an app that needs to read a PDF file from the file
We have an app that needs to access network resources. It's written in VB.Net.
I have an app that needs to be able use either an sqlite3 datebase
I have an app that needs backgrounds for both parts of the split view.

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.