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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:55:19+00:00 2026-05-20T20:55:19+00:00

I need to process multiple data values in parallel (SIMD). I can use the

  • 0

I need to process multiple data values in parallel (“SIMD”). I can use the java.util.concurrent APIs (Executors.newFixedThreadPool()) to process several values in parallels using Future instances:

import java.util.concurrent.{Executors, Callable}

class ExecutorsTest {
  private class Process(value: Int)
      extends Callable[Int] {
    def call(): Int = {
      // Do some time-consuming task
      value
    }
  }

  val executorService = {
    val threads = Runtime.getRuntime.availableProcessors
    Executors.newFixedThreadPool(threads)
  }

  val processes = for (process <- 1 to 1000) yield new Process(process)

  val futures = executorService.invokeAll(processes)

  // Wait for futures
}

How do I do the same thing using Actors? I do not believe that I want to “feed” all of the processes to a single actor because the actor will then execute them sequentially.

Do I need to create multiple “processor” actors with a “dispatcher” actor that sends an equal number of processes to each “processor” actor?

  • 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-05-20T20:55:19+00:00Added an answer on May 20, 2026 at 8:55 pm

    If you just want fire-and-forget processing, why not use Scala futures?

    import scala.actors.Futures._
    def example = {
      val answers = (1 to 4).map(x => future {
        Thread.sleep(x*1000)
        println("Slept for "+x)
        x
      })
      val t0 = System.nanoTime
      awaitAll(1000000,answers: _*)  // Number is timeout in ms
      val t1 = System.nanoTime
      printf("%.3f seconds elapsed\n",(t1-t0)*1e-9)
      answers.map(_()).sum
    }
    
    scala> example
    Slept for 1
    Slept for 2
    Slept for 3
    Slept for 4
    4.000 seconds elapsed
    res1: Int = 10
    

    Basically, all you do is put the code you want inside a future { } block, and it will immediately return a future; apply it to get the answer (it will block until done), or use awaitAll with a timeout to wait until everyone is done.


    Update: As of 2.11, the way to do this is with scala.concurrent.Future. A translation of the above code is:

    import scala.concurrent._
    import duration._
    import ExecutionContext.Implicits.global
    
    def example = {
      val answers = Future.sequence(
        (1 to 4).map(x => Future {
          Thread.sleep(x*1000)
          println("Slept for "+x)
          x
        })
      )
      val t0 = System.nanoTime
      val completed = Await.result(answers, Duration(1000, SECONDS))
      val t1 = System.nanoTime
      printf("%.3f seconds elapsed\n",(t1-t0)*1e-9)
      completed.sum
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to spawn a process in Java (under Linux exclusively) that will continue
The task is - need to process multiple I/O streams (HTTP downloads) with some
I am currently in the thinking process of the data structure I might use
I am currently in the process of designing a system which will use multiple
Scenario: Data is received and written to database with timestamps. I need to process
I need to process a large file, around 400K lines and 200 M. But
Using C++ (and Qt), I need to process a big amount of 3D coordinates.
I have a quite big XML output from an application. I need to process
Parts of my application are in C++ under windows. I need the process id
I am launching a child process with ProcessBuilder, and need the child process to

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.