If I am using any unsynchronized class, how do I make sure I handle synchronization externally? Is this good enough:
public class Test{
private ArrayList al = new ArrayList();
private synchronized void add (T t){
al.add(t);
}
private synchronized void remove (T t){
al.remove(t);
}
....
....
....
}
I will make sure any add/delete in other methods will call these two adder deleter methods. But correct me if was wrong, this way only ensure 2 threads are adding and 2 threads are deleting. It does not handle that 1 thread is adding, and at the same time, 1 thread is deleting. How do I handle that?
Thanks.