java - Synchronise ArrayList over two threads -
i'm having difficult time understanding how synchronise arraylist on 2 threads. basically, want 1 thread appending objects list , other 1 reading list @ same time. here class deploys threads: public class main { public static arraylist<good> goodlist = new arraylist(); public static void main(string[] args) { thread thread1 = new thread(new goodcreator()); thread thread2 = new thread(new weightcounter()); thread1.start(); thread2.start(); } } then 2 runnable classes: this 1 reads lines of 2 values text file , appends new objects. public class goodcreator implements runnable{ private arraylist<good> goodlist = main.goodlist; private static scanner scan; @override public void run() { system.out.println("thread 1 started"); int objcount = 0; try { scan = new scanner(new file(system.getproperty("user.home") + "//goods.txt")); } ...