If you do something like:
class MyThreadRunnable implements Runnable { List<String> strings; MyThreadRunnable(List<String> strings) { this.strings = strings; } public void run() { strings.add(getName()); } }
then both t1 and t2 (two different threads of the same type) will use the same list and see the changes made from another thread.
In fact, since I do not use synchronization for brevity, it is also possible that this can lead to incorrect list corruption and cause strange errors. I highly recommend that you investigate process synchronization and the java.util.concurrent package when working with concurrency.
source share