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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:06:37+00:00 2026-06-07T04:06:37+00:00

If I have 2 CPUs and schedule 1000 tasks for the fork / join

  • 0

If I have 2 CPUs and schedule 1000 tasks for the fork / join framework to work on, will the tasks be executed in a maximum of 2 at a time, or will more tasks be executed in parallel on the same CPU? (say, maybe one task is waiting for I/O, in which case the CPU would become idle and another thread could run)

  • 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-07T04:06:39+00:00Added an answer on June 7, 2026 at 4:06 am

    I made a test to verify this:

    import java.util.concurrent.*;
    
    public class Test {
        private static class TestAction extends RecursiveAction {
            private int i;
    
            public TestAction(int i) {
                this.i = i;
            }
    
            protected void compute() {
                if (i == 0) {
                    invokeAll(new TestAction(1), new TestAction(2), new TestAction(3),
                              new TestAction(4), new TestAction(5), new TestAction(6));
                    return;   
                }             
                System.out.println(i + " start");
                try { Thread.sleep(2000); } catch (Exception e) { }
                System.out.println(i + " end"); 
            }   
        }       
    
        public static void main(String[] args) {
            new ForkJoinPool().invoke(new TestAction(0));
        }   
    }       
    

    The results of that running with the reference Oracle implementation is:

    1 start
    6 start <- wait 2 seconds
    1 end
    2 start
    6 end
    5 start <- wait 2 seconds
    2 end
    3 start
    5 end
    4 start <- wait 2 seconds
    4 end
    3 end
    

    The same behavior is consistent on both Linux and Mac OS X.

    So the answer to the question is: yes, the tasks will be executed on exactly the number of CPUs specified by the parallelism parameter (or the total available CPUs by default). If CPU time becomes available and the tasks simply block waiting for something, then the framework will do nothing automatically to run other tasks.

    Since the documentation I’ve seen so far is pretty vague about what exactly the framework is supposed to do if the CPU is free, this could be an implementation detail.

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

Sidebar

Related Questions

Suppose I have to ехеcute several CPU-bound tasks. If I have 4 CPUs, for
I have 2 questions: 1. Can a machine have two or more CPUs which
I have performance critical code written for multiple CPUs. I detect CPU at run-time
have written this little class, which generates a UUID every time an object of
Have 2 tables in Access 2007, both lists of certain tasks to be accomplished.
Modern x86 CPUs have the ability to support larger page sizes than the legacy
Can two CPUs hold two different spin locks simultaneously at same time? So...does this
I always wondered what's the purpose of the rotate instructions some CPUs have (ROL,
Say I have a bitmap, and several threads (running on several CPUs) are setting
Once upon a time, to write x86 assembler, for example, you would have instructions

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.