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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:07:38+00:00 2026-06-06T12:07:38+00:00

class A { static Map<String,ColA> mapA; static const int a = 12; static Map<String,colB>

  • 0
class A {
static Map<String,ColA> mapA;
static const int a = 12;
static Map<String,colB> mapB;
}

Q1>
Now I need to update the Map from database every 10 minutes. There can be multiple threads which can be accessing mapA. So if I update in one of the threads using synchronized how will there be any instance where the thread may break when the updating is going on. If so how to solve this problem??

Q2>
Also I have different member of the class. Some of them are constants and some of them are loaded from memory. However all of them have one common property. They are always the same for all the instances (static). So does it make sense to have everything in one class or should we have two separate classes?

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-06T12:07:39+00:00Added an answer on June 6, 2026 at 12:07 pm

    Now I need to update the Map from database in every 10 minutes. There can be multiple thread which can be accessing mapA. So if i update in one of the thread using synchonized how will there be any instance where the thread may break when the updation is going on. If so how to solve this problem??

    This sounds like somewhere it might be worth using AtomicReference. Fetch the data from the database, put it in a map, and then atomically swap it with the “old” map. That way any client code can fetch the map and know that it’s effectively a snapshot which won’t change under them.

    Also I have different member of the class. Some of them are constants and some of them are loaded from memrory. However all of them have one common property. They are always same for all the instances(static). So does it make sense to have everything in one class or should we have two seperate class.

    That’s a pretty vague description. None of the attributes you’ve specified (some being constants, some being loaded from memory, all having one common property, all being static) have anything to do with whether they should be in the same class or not.

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

Sidebar

Related Questions

VERSION 1 class Doh { private: static std::map<const std::string, const Doh*> someMap; std::string stringValue_;
I have a static std::map<std::string, CreateGUIFunc> in a class that basically holds strings identifying
public ref class ScriptEditor : public Form { public: typedef map<UInt32, ScriptEditor^> AlMap; static
I'm looking for a parser that can extract methods from a java class (static
class Program { static void Main(string[] args) { List<Book> books = new List<Book> {
class C{ static int f1(int i) { System.out.print(i + ,); return 0; } public
class Program { static void Main(string[] args) { string value = "12345"; Type enumType
I have a class with a static std::map member variable that maps char s
I have a map between string and a class object. I populate this map
public static class Map extends MapReduceBase implements Mapper MapReduceBase , Mapper and JobConf are

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.