How Does Java List Global Variable Manage Insert, retrieve & Remove Items when many Insert/retrieve, remove functions are accessing it? -


ok, want store chat messages global variables instead of db because system not use relational db. uses nosql google datastore , write , read data datastore expensive.

let see java list global variable

public list mylist = new arraylist(); 

now have 3 functions:

public void insert(){    mylist.add(string); }  public void remove(){    mylist.remove(string); }  public void retrieve(){     string str = mylist.get(i);     // } 

suppose insert, retrieve , 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 case, how java list global variable manage insert, retrieve & remove items when many insert/retrieve, remove functions accessing it?

does adhere rules can know how control properly?

arraylist not thread-safe , concurrentmodificationexception.

use collections.synchronizedlist() instead.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -