lately playing around semaphores , multithreading, when noticed, weird going on array list. more details:
i have class single private arraylist:
public class newclass{ private arraylist list = new arraylist(); public void put(object val){ list.add(val); } public void del(object val){ list.remove(val); } }
from thread, i'm trying remove elements (without putting before that):
public class someclass { public static void main(string[] args) throws interruptedexception { new someclass(); } public someclass() throws interruptedexception { thread tr2 = new thread() { @override public void run() { newclass nc = new newclass(); (int = 0; < 100; i++) { nc.del(i); } } }; tr2.start(); } }
and when thread starts working - have no errors, no exceptions, etc. while, if debugging, can see, list.indexof(val); return -1 value - not exist, "removed". can explain going on here?
lists don't throw exceptions if try remove things aren't in remove(object o) method. return false.
Comments
Post a Comment