Ok, I want to store chat messages into Global variables instead of DB because my system does not use Relational DB. It uses NoSQL Google datastore and write and read data from datastore could be expensive.
Let see this Java List Global Variable
public List myList = new ArrayList();
Now we have 3 functions:
public void insert(){
myList.add(string);
}
public void remove(){
myList.remove(string);
}
public void retrieve(){
String str = myList.get(i);
// do something
}
Suppose that insert, retrieve and remove run concurrently every X seconds
Timer timer = new Timer();
timer.schedule(new insert(), 0, 5000);
timer.schedule(new remove(), 0, 3000);
timer.schedule(new retrieve(), 0, 4000);
If that is the case, then how does Java List Global Variable Manage Insert, Retrieve & Remove Items when many Insert/retrieve, remove functions are accessing it?
Does it adhere to some certain rules so that we can know how to control it properly?