I'm working on an android game and I just noticed that since onTouchEvent
runs on the UI thread, and the update/render methods are ran from a separate threads, both of them update an ArrayList
which contains the entities. So obviously they conflict if they happen to modify the list at the same time.
I read that Vector
class is used exactly the same as ArrayList
with the only difference that Vector
is synchronized, ergo they wont conflict. Is that true? if so, does it have any performance issue or something that I should be concerned about? I have never used Vector
class before.
EDIT: what I actually meant was change from
ArrayList<Obj> list = new ArrayList<Obj>();
to
Vector<Obj> list = new Vector<Obj>()
But as the answers say, Vector
is not recommended to use. The selected answer solved my issue.