Multithreading
Multithreading Inter-thread communication Each thread has its own stack, which also means its own copy of shared global variables ( static and non-static both ). so updates from one thread may not necessarily be visible to another in time. This will cause inconsistencies. This is especially important in multi-core systems where each thread might end up on a different core and each core may have it its own local cache which the thread is using. The updates by one thread may not be readily synced with main cache and hence not visible to other threads. The same issue may also arise due to compiler optimizations; the sequence of instructions may get reordered by jvm and compiler. This will still produce consistent results within single thread but other threads are not guaranteed to see this consistency. Java provides two ways to deal with these issues. synchronized access, volatile variables. When you try to have synchronized access of a code block or method, only one