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

  • Home
  • SEARCH
  • 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 6359549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:31:58+00:00 2026-05-24T23:31:58+00:00

I have a thread running, calling out to an external web service to retrieve

  • 0

I have a thread running, calling out to an external web service to retrieve some data. The thread should however exit the run method when a certain condition is met in a database (count number of rows of certain type and see if they equal a value). I am thinking of implementing this and have thought of the following ways.

  1. Processing thread:

        run() {
    
                while(not [db call to get row count] = expected number ) {
    
                   call web service
    
                   // wait for some time for the next call? not sure
                   // if this is the way to do it
                   Thread.sleep(200);   
                }
        }    
    
  2. Have an external thread monitoring the database status and updating an AtomicBoolean variable.The processing thread woud check this variable in the while loop every time.

    ProcessingThread:

    private Runnable dbStatusThread;
    run() {
    
       while(dbStatusThread.booleanValue == false) {
          call web service
    
              // wait for some time for the next call
          Thread.sleep(200);    
       }
    }
    

I tried implementing the second option, but even though the boolean is set to true, it isn’t always reflected and the run() doesn’t always immediately exit. I’m reading JCIP as I write this, but does anyone know of a standard way of doing this kind of thing? 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-24T23:31:59+00:00Added an answer on May 24, 2026 at 11:31 pm
    @Override 
    public void run() {
       while (db.getNumLinesOfWantedType() >= wantedNum) {
          webServiceFillDB();
       }
       // The thread terminates here when the database has enough lines.
    }
    

    I did not put an == in the condition but a >= instead since maybe you’ll get more lines than you want.

    Even if some other process or thread is filling the database at the same time this code is valid. If there is no other process filling the database, you could just have a for-loop calling the web service a set number of times, without checking the database at each step.

    Note that a database is kind of “synchronized” to start with: when you check the number of lines in the database, you get the current picture.

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

Sidebar

Related Questions

I am running a thread in C#. I have web form. I declared public
I have a separate thread running to get data from the internet. After that,
I have service with thread, From activity I am calling start service(from Activity::onDestroy()) and
Let's say I have 10 threads running simultaneously. Is there any way of calling
I have a thread running in the background. How do i send it messages
I have a background thread running that fires events, but how can I ensure
I have my main GUI thread, and a second thread running inside it's own
I have a thread in my application that is running code that can potentially
I have a TableModel that is populated from a background running thread. I am
In my C# program, I have a thread that represents a running test, which

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.