Distributed computation is about time and state. That is, in order for more than one component to communicate, state must be shared, and all that takes time.
Most programmers anthropomorphize their work. They think about one thread of control carrying out the entire program in the same way they would if they had to do the job themselves. Modern computers, however, switch between tasks very quickly, and in multi-core, multi-CPU, or distributed systems, two events may take place at exactly the same time. Defects rush to fill the gap between the programmer's model of how a program executes and what happens in reality. These defects are related to unexpected interactions between threads, processes, time, and information. These interactions happen through shared state: semaphores, variables, the file system, and, basically, anything that can store information.
J2EE Bad Practices: Non-Serializable Object Stored in Session
HttpSession
attribute can damage application reliability.HttpSession
object across multiple JVMs so that if one JVM becomes unavailable another can step in and take its place without disrupting the flow of the application.In order for session replication to work, the values the application stores as attributes in the session must implement the
Serializable
interface.Example 1: The following class adds itself to the session, but because it is not serializable, the session can no longer be replicated.
public class DataGlob {
String globName;
String globValue;
public void addToSession(HttpSession session) {
session.setAttribute("glob", this);
}
}