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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:38:43+00:00 2026-06-07T20:38:43+00:00

I am getting my hands dirty with Java 7 concurrency and parallelism feature –

  • 0

I am getting my hands dirty with Java 7 concurrency and parallelism feature – Fork/Join Framework.

I am trying to display the list of all directories under a given path. Can some one tell me if I got this correct?

Here is my main class – JoinForkExample that kicks off the task

package com.skilledmonster.examples;

import java.io.File;
import java.util.List;
import java.util.concurrent.ForkJoinPool;

public class JoinForkExample {
    public static void main(String[] args) {
        ForkJoinPool forkJoinPool = new ForkJoinPool() ;
        List<File> directories = forkJoinPool.invoke(new DirectoryListingTask(new File("C:/xampp"))) ;
         for (int i = 0; i < directories.size(); i++) {
            File file = (File) directories.get(i);
            System.out.println(file.getAbsolutePath());
        }
    }
}

And here is my actual task

package com.skilledmonster.examples;

import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.RecursiveTask;

public class DirectoryListingTask extends RecursiveTask<List<File>> {

    private static final FileFilter filter = new DirectoryFilter();

    private File file ;

    public DirectoryListingTask(File file) {
        this.file = file;
    }

    @Override
    protected List<File> compute() {
       List<RecursiveTask<List<File>>> forks = new LinkedList<>(); 
       List files = new ArrayList();
        if (file.isDirectory()) {
            File[] filteredFiles = file.listFiles(filter);
            if (null != filteredFiles) {
                files.addAll(Arrays.asList(filteredFiles));
            }
            for (File childFile : file.listFiles()) {
                DirectoryListingTask task = new DirectoryListingTask(childFile);
                forks.add(task);
                task.fork();
            }

            for (RecursiveTask<List<File>> task : forks) {
                files.addAll(task.join());
            }
        }
        return files ;
    }
}

I am pretty much getting the intended result. But I am not quite sure if I got this right. And surprising I don’t notice any time difference in execution even when I executed the same without using join/fork framework.

Any thoughts!

  • 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-07T20:38:44+00:00Added an answer on June 7, 2026 at 8:38 pm

    As this work is primarily IO-bound, it’s not very helpful to use Fork/Join here. I would suggest to try some computation intensive task instead. Also, please note the Fork/Join operation has overhead. If you use it to compute Fibonacchi series, it won’t deserve it. And I would expect that performance is slower than sequential version.

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

Sidebar

Related Questions

HTML <div class=productDescriptionWrapper> <p>A worm worth getting your hands dirty over. With over six
I'm just getting my hands dirty with class-based views. What is the correct way
I've been getting my hands dirty lately working on development for the iPhone. Development
I am new to Castle Project ActiveRecord. I have starting getting my hands dirty
I am getting my hands on TFS 2010, and I am starting with trying
I'm very much interested in getting my hands dirty to run Symfony2 Application on
Getting a 'marshal data too short' error when trying to install the mysql gem
I'm a web developer and I'm getting envious of all the cool iPhone apps.
I've been getting my hands wet with emacs lisp, and one thing that trips
I am trying my hands on sample codes from a book, and so I

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.