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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:38:09+00:00 2026-06-08T20:38:09+00:00

Here is my scenario: I have a master actor, which receives messages from multiple

  • 0

Here is my scenario:

I have a master actor, which receives messages from multiple child actors. These messages contain data to be aggregated. In this aggregation logic, do I need to take care of synchronization issues, if I use a shared data structure to collect the aggregation?

else if(arg0 instanceof ReducedMsg){

                           ReducedMsg reduced = (ReducedMsg)arg0;
        counter.decrementAndGet();

        synchronized(finalResult){

            finalResult.add((KeyValue<K, V>) reduced.getReduced());

            if(counter.get() == 0){
                                    if(checkAndReduce(finalResult)){

                    finalResult.clear();
                }
                else{
                    stop();
                    latch.countDown();
                }

            }

        }



    }

So as you can see I have a finalResult, to which each message will be aggregated, and after a processing logic the collection needs to be cleared as well.

Actually what I am trying to implement is a recursive (associative) reduction mapreduce. So I need to keep the synchronized block I assume? Or is it by any chance Akka executes the onReceive one thread at a time?

This logic produces accurate and predictable result on small data set. My problem is when my input data set is a little large, the code hangs. I want to be sure that is because of the context switches for my synchronization block, so that I may dwelve into a different design.

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

    onReceive() is never called concurrently. This is the most fundamental guarantee Akka is giving to you.

    This means that if your counter variable is a field in an actor and no other piece of code can access that field directly, you can safely use normal int/long instead of AtomicInteger/AtomicLong. Also synchronization on finalResult is not necessary assuming it is a field encapsulated and hidden in an actor.

    Finally the usage of CountDownLatch is suspicious. In Akka applications you shouldn’t use any synchronizations primitives. Actors are essentially single-threaded and all communication (including waking up and passing data) should be implemented via message passing.

    This is all explained in the documentation: http://doc.akka.io/docs/akka/2.0.2/general/jmm.html#Actors_and_the_Java_Memory_Model

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

Sidebar

Related Questions

Here's the scenario: I have an asp.net webpage which displays dynamic data in a
Here is the scenario: I have a visual that displays some data The data
Here's the scenario: I have 2 tables with data, one is the 2009 version
Here is the scenario: I have 1 master page and web-forms in that master
Good afternoon all Here is my scenario: I have user controls within a master
Hey Gitters. Here's the scenario: I have my master with a directory we'll call
Here is my scenario: I have the following menu created from a viewModel <ul>
Here is the scenario: I have successfully bound two objects from a native ObjC
I have a master-detail scenario where I have 1 ComboBox listing companies from an
Here is the deal. I have a Master-Detail Grid scenario. The Master GridView is

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.