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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:46:42+00:00 2026-06-18T00:46:42+00:00

how lets say i have this class @ImmutableWannabe public class ConfigurationHolder { @ImmutableButHowToMakeSureNoTwoThreadsOverrideOneEachOtherWhenReplacingReference private

  • 0

how

lets say i have this class

@ImmutableWannabe
public class ConfigurationHolder {
  @ImmutableButHowToMakeSureNoTwoThreadsOverrideOneEachOtherWhenReplacingReference
  private Map<System, Configuration> mySysConfig  = ImmutableMap.builder<>getSomeConfigurations....build();
  ConfigurationHolder(copy constructor) {
     mySysConfig = ImmutableMap.builder().of(inputSysConfig);
  }
}

Now lets say one of the systems configuration has updated and i need to update this map of however I need to do it in a thread safe way. which means if two threads try to update the same configuration of same system data should be consistent and they should not override one each other.

How did immutability help me here? As far as i can see i still need to do locking if yes how to do it properly?

so my general question is: isn’t it the case that any immutableObject which can change over system time will cause us to need to lock the code that will need to change its ImmutableObjectHolder? I don’t get it…

can someone please give a proper example of an ImmutableMap + Holder for that Map + proper “client” code that knows to update this ImmutableMapHolder with updates to the internal Map?

thanks

  • 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-18T00:46:43+00:00Added an answer on June 18, 2026 at 12:46 am

    Assuming your map is some instance variable, the simplest way it to make it volatile. Alternatively, make a getter and setter for it and make them synchronized. i.e., use standard techniques. And note that this won’t help if the client tries to be clever and cache the value in a local variable. (I’ve bitten myself with this bug a couple of times.)

    I guess as an alternative you could setup some MyImmutableChanged event/listener.

    And, you are correct, immutability doesn’t solve every threading problem.

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

Sidebar

Related Questions

lets say I have my owndefined datatype like this: public class InformationType { private
Lets say have this immutable record type: public class Record { public Record(int x,
Lets say i have this usercontrol public class test : UserControl { public int
Lets say I have a class like this in Java: public class Function {
Lets say i have this class: class Test123<T> where T : struct { public
Lets say I have this class class Child { public string FirstName { get;
Lets simplify. Lets say I have this class: class Foo { public string Name
Lets say I have this amputated Person class: class Person { public int Age
Lets say I have a class as below: public class class1{ private int[] array1;
lets say I have the following public class A { private string _someField; public

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.