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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:32:47+00:00 2026-06-08T22:32:47+00:00

I am creating, say, 15 Callable tasks, and submitting them: List<Future<MyResult>> futures = new

  • 0

I am creating, say, 15 Callable tasks, and submitting them:

List<Future<MyResult>> futures = new ArrayList<Future<MyResult>>();
List<MyResult> myResults = new ArrayList<MyResult>();

for(int i = 1; i <= 15; i++){
    Callable<MyResult> task = new MyProcessor(//parameters);
    Future<MyResult> future = executorService.submit(task);
    futures.add(future);//used to iterate over to call get() to collect results in next for loop
}

Then I am collecting the 15 MyResult objects:

for(Future<MyResult> future : futures){
  try {
    MyResult myResult = future.get();
    processorResults.add(myResult);
    } catch (InterruptedException e) {
      //...
    } catch (ExecutionException e) {
      //...
    }
}

Issue is: Instead of getting ALL 15 MyResult objects back from the get() method, I am sometimes getting less than 15 objects back. Sometime 12 sometimes 10 sometimes even lesser, and sometimes all 15.

I was under the impression that get() method is a blocking call and will wait for ALL 15 threads to get back with respective results, but looks like I miss a few of them and move ahead.
What is it that I am doing wrong? Am I not collecting the results/ waiting for the results correctly? Does this happen when an ERROR is thrown from any of the MyProcessor task?

  • 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-08T22:32:49+00:00Added an answer on June 8, 2026 at 10:32 pm

    It could mean that some of your jobs threw an exception. It is hard to tell from your code but you need to do something with ExecutionException other than catching and ignoring it.

    Future.get() throws ExecutionException when the Callable you submitted throws a RuntimeException from the call() method. It will only return your MyResult if the method returns normally with return. You can get the exception that was thrown by doing:

    } catch (ExecutionException e) {
        // account for the throw here, the original exception is in e.getCause()
        // log it, count it, or ...
        logger.error("Job threw exception: " + e.getCause());
    }
    

    I was under the impression that get() method is a blocking call and will wait for ALL 15 threads to get back with respective results,

    This is correct. When you call future.get() that will block until the job either finishes — either by throwing an exception or returning. If the thread that is going the get() is interrupted then the get() throws an InterruptedException which also should be caught and not just ignored.

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

Sidebar

Related Questions

OK, let's say I am creating a program that will list users contacts in
I am creating an interface say 'Car' public interface Car { public void drive(int
How does one go about creating multiple new users, say in a loop, from
Say i'm creating an email list. How would I validate the field to not
Let's say I have a View for creating a new Item. Item consists of
I'm creating a new object that takes a string and a class. Let's say
I'm creating a list of plots (by ggplot2 ) using lapply let's say I
Im new to creating array and had a question. Say if you are creating
Say I am using git by creating a new branch for each feature, then
If I am creating say a input field through MXML , I can set

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.