Lets say I have two threads A and B and inside these both 2 threads I have synchronized
block in which an int
variable is modified continously.
For example, thread A
enter synchronized block modify int variable then call these 2 methods:
notifyall(); //to wake thread B which is in waiting state and
wait():
and after that thread B
acquire lock and do same steps as thread A and process keep on repeating. All changes to int variable happens inside synchronized block of both threads.
My question is do I need to make int variable volatile
. Do thread flush to main memory before they go to waiting state and reload data in registers when thread acquire lock again as a result of notifyall();
call.