java - Synchronization when managing a database like class -


data represents in memory "database" 5-10 threads use through service class. how should go around synchronizing , updating these 2 maps hold overlapping information , should updated each time modified or added first one, without using immutable classes , use of locks (since infoblock have recreated due amount of money changing rapidly)?

is use of "long" value case correct?

public class data {      private map<string, infoblock> map1;     private map<string, long> map2;      public data() {         map1 = new concurrenthashmap<>();         map2 = new concurrenthashmap<>();     }      /* methods combine both maps */  }  public final class infoblock {      private final long money;     private final string name;      public infoblock(long money, string name) {         this.money = money;         this.name = name;     }      public long getmoney() {return money;}     public string getname() {return name;} } 


Comments