Thread data and consistency
Before getting Java EE-specific, it is important to step back a moment and understand the implications of concurrency on the programming model.
Concurrent data access
When a single thread accesses data, then the access is always thread-safe, and it is not possible for a thread to mutate data while another one is reading it. When you increase the number of threads and multiple threads can access the same data structure instances, it is possible for a thread to read the data that's currently being modified, or for two concurrent modifications to happen, leading to an inconsistent result.
Here is a schema representing this issue with two threads. Keep in mind that a Java EE server often handles around 100 to 1000 threads, so the effects are more impacting:

In this simple example, we have a thread (Thread 1) setting data that is supposed to be a complex structure. In parallel, we have another thread (Thread 2) accessing the data. In the preceding diagram, the very thin...