Nó luôn luôn an toàn để bộ nhớ cache một tham chiếu đến một giao diện chủ EJB địa phương. Mặc dù các đặc điểm kỹ thuật EJB (§ ) có nghĩa là nó an toàn để bộ nhớ cache một ngôi nhà từ xa, có một cơ hội nhỏ mà một nhà tài liệu tham khảo từ xa lưu trữ có thể trở thành "cũ" trong một số máy chủ | Reference data that can be shared between users should always be held at application level. Data that is unlikely to be reused should probably just be retrieved again if it s ever needed. For example a primary key might be held instead of a large volume of data retrieved from a database this is a good sacrifice of performance in rare cases for a real benefit in scalability. Use Fine-grained Rather than Large Monolithic Session State Objects It s usually best to break session state into a number of smaller objects than one large composite object. This means that only those objects that have changed will need replication in a cluster. As there s no easy way to establish whether the state of a Java object has changed some servers such as WebLogic only replicate session state in a cluster when an object is rebound in an HttpSession although the Servlet specification doesn t specify what behavior is expected here. The Servlet specification may define standard semantics for session replication. Such selective replication can deliver a big performance gain when objects stored in a session are updated at varying rates. Thus to ensure correct replication behavior always rebind a session attribute when the session data is changed. This won t pose a problem in any server. Consider Optimizing the Serialization of Session Data Sometimes by overriding the default serialization behavior we can greatly improve the performance and reduce the size of serialized objects. This is a specialized optimization that is rarely necessary. We ll discuss serialization optimization in Chapter 15. Session State Held in the Browser Some session state must always be held in the user s browser. As HTTP is a stateless protocol a J2EE server can only retrieve a user s session object if it finds a cookie or a special request parameter containing a unique key for that user s session. By holding session state in the browser we lose the advantage of transparent server management of session state