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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:40:33+00:00 2026-06-05T18:40:33+00:00

So what I am doing is, I have a loop and I call a

  • 0

So what I am doing is, I have a loop and I call a AsyncTask inside my loop, so there might be a bunch of them. From my understanding is, after the loop is done I can’t just display a message that everything is complete, because the message will appear before the AsyncTasks are done, since thats kinda the point of asynchronous threading.

If I would had just one AsyncTask it would be a nobrainer, I would put my code to display a message into onPostExecute() but now I have many of them.

So is there a way of knowing when all the AsyckTast threads are all finished so I can show my message?

Thanks for you answer in return, as you might have guess, I am kinda new to Java.

  • 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-06-05T18:40:34+00:00Added an answer on June 5, 2026 at 6:40 pm

    Try with a static Integer that increments for every AsyncTask created and in onPostExecute() decrement it. When it reaches 0 all your task will be finished.

    E.g.:
    when task is created:

     synchronized(staticInt) {
        //create AsyncTask
        ++staticInt;
     }
    

    And when it finishes:

     protected void onPostExecute(Object result) {
         synchronized(staticInt) {
            --staticInt;
            if (staticInt == 0) {
               //show message
            }
         }
     }
    

    As @James suggested, you could also use it to control the maximum number of AsyncTask executing at a certain time:

     while (staticInt >= MAX_NUMBER_OF_THREADS) {
         //wait
     }
    
     synchronized(staticInt) {
        //create AsyncTask
        ++staticInt;
     }
    

    It can be improved with a wait-notify approach.

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

Sidebar

Related Questions

I have two tables (let's call them TradingWindows and VolumeData). Each row of TradingWindows
I have a tricky question. My java program is doing in a loop such
I have this function, which is doing an asynchronous call to FB.api method. Now,
I have been doing some research on test driven development and find it pretty
I have been doing active development in C# for several years now. I primarily
I have been doing TDD and was using it more as unit testing than
I have been doing PHP stuff for almost one year and I have never
anyone have experience doing this? when i say imaginary i mean the square root
i have strange problem doing reporting: i have numerous clients with different issued invoices.
I have been doing a lot of unit testing lately with mocking. The one

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.