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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:55:02+00:00 2026-06-13T12:55:02+00:00

I…really don’t know how to word the title better. But basically, what I have

  • 0

I…really don’t know how to word the title better. But basically, what I have is a thread pool with all these threads busily working. I want them to report their results in the order that they were assigned, but at the same time, I want to work in batches. To illustrate, and example would be

ExecutorService exec = Executors.newFixedThreadPool(8);

class MyCallable implements Callable<byte[]> {
    private final int threadnumber;

    MyCallable(int threadnumber){
        this.threadnumber = threadnumber;
    }

    public byte[] call() {
        //does something
    }
}
List<Callable<byte[]>> callables = new ArrayList<Callable<byte[]>>();

for(int i=1; i<=20; i++) {
    callables.add(new MyCallable(i));
}
try {
    List<Future<byte[]>> results = exec.invokeAll(callables);
    for(Future<byte[]> result: results) {
            System.out.write(result.get(), 0, result.get().length);
    }

Basically, the pool thread has 8 threads and I end up having 20 tasks (these are just examples). The way this works now, if I understand correctly, is that it waits until ALL 20 tasks are done before outputting them in order (from 1 to 20). What this program is supposed to do is output a continuous stream of bytes (which were processed by threads, and since I need to keep the order intact, I used the future interface). While I don’t mind waiting until all 20 tasks are done, is there anyway so that the threads simply output in order as they go.

If there’s no way or I’m just completely misunderstanding how invokeAll works, clarification there is welcome too. Thanks a bunch in advance! Executors are a bit confusing since I only just learned about them.

Random addendum, am I even allowed to return a byte array from a callable?

  • 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-13T12:55:03+00:00Added an answer on June 13, 2026 at 12:55 pm

    invokeAll() waits until all results are computed before it returns.

    Use a loop and submit() them one by one instead, this method returns a Future with the pending result immediately:

    ...
    for(int i=1; i<=20; i++) {
        results.add(exec.submit(new MyCallable(i))); 
    }
    try {
        for(Future<Integer> result: results) {
                System.out.write(result.get(), 0, result.get().length);
        }
    }
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an element like this: <span class=tool_tip title=The full title>The ful&#8230;</span> This seems
I have this xml <entry id=1008 section=articles> <excerpt><p>&#8230; in Richtung „Aus für Tierversuche. Kosmetik-Fertigprodukte
CGI.escapeHTML is pretty bad, but CGI.unescapeHTML is completely borked. For example: require 'cgi' CGI.unescapeHTML('&#8230;')
so I did $subject = 'sakdlfjsalfdjslfad <a href=something/8230>lol is that true?</a> lalalala'; $subject =
I have been making a wordpress template. i got stuck at some place... the
Why does the Android system throw this Exception? 05-18 12:33:44.169 W/System.err( 8230): java.io.IOException: Is
I see that some rss on xml have strange strings. For example, ... is
I have a form, one of the fields is a select field, with 5
I have a PDB file. Now it has two parts separated by TER. Before
I'm operating with huge CSV files (20-25Mln rows) and don't want to split them

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.