Does SwingUtilities.invokeLater
provides synchronization?
Example:
public class Threads {
public static void main(String[] args) {
new Thread(new Runnable() {
@Override
public void run() {
new Threads().test();
}
}).start();
}
List<Integer> list = new ArrayList<>();
void test() {
System.out.println(Thread.currentThread().toString());
for (int i=0; i<10000000; i++) {
list.add(i);
}
SwingUtilities.invokeLater(() -> {
System.out.println(Thread.currentThread().toString());
list.forEach(System.out::println); // list auto synchronized?
});
}
}
Would be list
synchronized when I read values from the list in AWT thread?