Ideally, it will read it simultaneously, but it is not safe in some cases.
For example, if you declare:
int i = 1;
Thread threadOne = new Thread() {
public void run() {
i++;
System.out.println("ThreadOne is " + i);
}
};
Thread threadTwo = new Thread() {
public void run() {
i++;
System.out.println("ThreadTwo is "+ i);
}
};
Thread threadThree = new Thread() {
public void run() {
i++;
System.out.println("ThreadThree is " + i);
}
};
threadOne.start();
threadTwo.start();
threadThree.start();
You can try several times and you will see the result varies. Without synchronization, all of thread will read and write the memory "randomly" OR "simultaneously" in the other word, depend on who finish first.
The result I get after run the program several times:
ThreadOne is 1
ThreadThree is 3
ThreadTwo is 2
ThreadOne is 3
ThreadThree is 3
ThreadTwo is 3
ThreadTwo is 2
ThreadThree is 3
ThreadOne is 2
As we can see, all three thread read the memory which contain int i randomly and update the int a by adding one. If one thread has added one, then another thread will read 2.
The system.out.println() is also a process. In the second attempt, it prints all 3s. It means after three thread has read int i and add 1, the final result of int i became 3. Then the system.out.println will all print 3. Here is another way to prove, among all these threads, all the process are running simultaneously or the thread are running simultaneously.