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

  • Home
  • SEARCH
  • 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 8187957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:44:31+00:00 2026-06-07T02:44:31+00:00

I read about the implementation of the Fork/Join framework that was introduced in Java

  • 0

I read about the implementation of the Fork/Join framework that was introduced in Java 7 and I just wanted to check that I understand how the magic works.

As I understand, when a thread forks, it creates subtasks in its queue (which other thread may or may not steal). When the thread attempts to “join”, it actually checks its queue for existing tasks and then recursively perform them, which mean that for any ‘join’ operation – 2 frames will be added into the thread call stack (one for the join and one for the new taken task invocation).

As I know that the JVM does not support tail call optimization (that may serve in this situation to remove the join method stack frame) I believe that while performing a complicated operation with a lot of forks and joins a thread may throw an StackOverflowError.

Am I right or did they find some cool way to prevent it?

EDIT

Here is a scenario to help clarifying the question:
Say (for simplicity) that we only have one thread in the forkjoin pool.
At some point in time – the thread forks and then calls join. While in the join method the thread discovers that it can perform the forked task (as it found in its queue) so it invokes the next task. This task in turn forks and then call join – so while executing the join method the thread will find the forked task in its queue (like before) and invoke it.
in that stage the call stack will contain at least the frames for two joins and two tasks.

as you can see the fork join framework transformed to plain recursion. Because java does not support tail call optimization – every recursion in java can cause StackOverflowError if it goes deep enough.

My question is – did the implementer of the fork/join framework find some cool way to prevent this situation.

  • 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-07T02:44:33+00:00Added an answer on June 7, 2026 at 2:44 am

    There is unfortunately nothing magical happening in terms of the thread recursive stack. If your initial task forks/splits and doesn’t have a reasonable resolution point then you will run into StackOverflowErrors.

    You can probably understand why the tutorial on the JavaDoc splits each subtask in half.

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

Sidebar

Related Questions

I've read that qsort is just a generic sort, with no promises about implementation.
I read about skipList implementation in C++ and I don't understand this random function
This is just something that's been puzzling me ever since I read about iterators
So i read a lot about why this implementation isn't thread-safe. But I didn't
I read about an inheritance feature in PostgreSQL that seemed pretty neat. Unfortunately I
You often read about immutable objects requiring final fields to be immutable in Java.
I've read about interfaces in Java and now I want to make an interface
I just read about how ASLR helps in preventing buffer overflow attacks and would
I recently read about the action bar implementation in android in the dev site.But
I have read about this function didReceiveMemoryWarning that actually hasn't really helped. I would

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.