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
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.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.