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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:24:40+00:00 2026-06-08T08:24:40+00:00

Suppose I need to process files in a given folder in parallel. In Java

  • 0

Suppose I need to process files in a given folder in parallel. In Java I would create a FolderReader thread to read file names from the folder and a pool of FileProcessor threads. FolderReader reads file names and submits the file processing function (Runnable) to the pool executor.

In Scala I see two options:

  • create a pool of FileProcessor actors and schedule a file processing function with Actors.Scheduler.
  • create an actor for each file name while reading the file names.

Does it make sense? What is the best option?

  • 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-08T08:24:41+00:00Added an answer on June 8, 2026 at 8:24 am

    I suggest with all my energies to keep as far as you can from the threads. Luckily we have better abstractions which take care of what’s happening below, and in your case it appears to me that you do not need to use actors (while you can) but you can use a simpler abstraction, called Futures. They are a part of Akka open source library, and I think in the future will be a part of the Scala standard library as well.

    A Future[T] is simply something that will return a T in the future.

    All you need to run a future, is to have an implicit ExecutionContext, which you can derive from a java executor service. Then you will be able to enjoy the elegant API and the fact that a future is a monad to transform collections into collections of futures, collect the result and so on. I suggest you to give a look to http://doc.akka.io/docs/akka/2.0.1/scala/futures.html

    object TestingFutures {
      implicit val executorService = Executors.newFixedThreadPool(20)
      implicit val executorContext = ExecutionContext.fromExecutorService(executorService)
    
      def testFutures(myList:List[String]):List[String]= {
    
        val listOfFutures : Future[List[String]] = Future.traverse(myList){
          aString => Future{
                            aString.reverse
                           }
         }
        val result:List[String] = Await.result(listOfFutures,1 minute)
        result
    
      }
    }
    

    There’s a lot going on here:

    • I am using Future.traverse which receives as a first parameter which is M[T]<:Traversable[T] and as second parameter a T => Future[T] or if you prefer a Function1[T,Future[T]] and returns Future[M[T]]
    • I am using the Future.apply method to create an anonymous class of type Future[T]

    There are many other reasons to look at Akka futures.

    • Futures can be mapped because they are monad, i.e. you can chain Futures execution :

      Future { 3 }.map { _ * 2 }.map { _.toString }

    • Futures have callback: future.onComplete, onSuccess, onFailure, andThen etc.

    • Futures support not only traverse, but also for comprehension

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

Sidebar

Related Questions

I need to copy files and directories within a directory. Suppose there is only
Suppose I have an array of nodes (objects). I need to create a duplicate
I need to create a SAS dataset from a binary file. My code is:
I need to find the open files of the current process in C Linux.
Suppose I've got a list of files file1 file 1 file2 a for...in loop
I need to be able to process an input file where there are 3
I need to glob ./../path/to/files/**/*.txt but instead of receiving matches like this: ./../path/to/files/subdir/file.txt I
I'm working on an application that's supposed to read and process flat files. These
Suppose I need to break out of three or four nested for loops at
Suppose we need to check three boolean conditions to perform a select query. Let

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.