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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:14:47+00:00 2026-06-14T09:14:47+00:00

I have a parser, and after gathering the data for a row, I want

  • 0

I have a parser, and after gathering the data for a row, I want to fire an aync function and let it process the row, while the main thread continues on and gets the next row.

I’ve seen this post: How do I execute two tasks simultaneously and wait for the results in Groovy? but I’m not sure it is the best solution for my situation.

What I want to do is, after all the rows are read, wait for all the async functions to finish before I go on. One concern with using a collection of Promises is that the list could be large (100,000+).

Also, I want to report status as we go. And finally, I’m not sure I want to automatically wait for a timeout (like on a get()), because the file could be huge, however, I do want to allow the user to kill the process for various reasons.

So what I’ve done for now is record the number of rows parsed (as they occur via rowsRead), then use a callback from the Promise to record another row being finished processing, like this:

def promise = processRow(row)
promise.whenBound {
    rowsProcessed.incrementAndGet()
}

Where rowsProcessed is an AtomicInteger.

Then in the code invoked at the end of the sheet, after all parsing is done and I’m waiting for the processing to finish, I’m doing this:

boolean test = true
while (test) {
    Thread.sleep(1000)  // No need to pound the CPU with this check
    println "read: ${sheet.rowsRead}, processed: ${sheet.rowsProcessed.get()}"
    if (sheet.rowsProcessed.get() == sheet.rowsRead) {
        test = false
    }
}

The nice thing is, I don’t have an explosion of Promise objects here – just a simple count to check. But I’m not sure sleeping every so often is as efficient as checking the get() on each Promise() object.

So, my questions are:

  1. If I used the collection of Promises instead, would a get() react and return if the thread executing the while loop above was interrupted with Thread.interrupt()?
  2. Would using the collection of Promises and calling get() on each be more efficient than trying to sleep and check every so often?
  3. Is there another, better approach that I haven’t considered?

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-06-14T09:14:49+00:00Added an answer on June 14, 2026 at 9:14 am
    1. Call to allPromises*.get() will throw InterruptedException if the waiting (main) thread gets interrupted
    2. Yes, the promises have been created anyway, so grouping them in a list should not impose additional memory requirements, in my opinion.
    3. The suggested solutions with a CountDownLanch or a Phaser are IMO much more suitable than using busy waiting.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a parser that we implemented and I want to compare it to
I have been using HTML Parser to scrapping data from websites and stripping html
I have been trying to add a button after a parser ( on a
I have an Android app which uses Jackson parser for JSON parsing. After I've
I am writing a custom textfile-data parser (JSON-like) and I have lost many hours
I have got a Wavefront OBJ Parser up running but after spending endless hours
I'm using android's SAX parser and I wish to stop processing after I have
I want to validate the string value after getting in the below parser delegate
I want to parse two files. I have Yacc/lex code which generates the parser.
I have a application, what is download a xml file and after parser it.

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.