Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I tested two approaches to store session data:

  • The classic: 1 key, 1 object (And every key as static final String in a class)

"user" --> UserObject

"preferences" --> List

...

  • An approach with only 1 object

"sessionObject" --> SessionObject

And my SessionObject contains UserObject and the list of preferences as attributes. This is a fairly simple example but imagine it with 20+ attributes.

The advantage I see in the second approach is that :

  • You only have to delete one key to ensure session is empty
  • You don't have to create the bothersome set of final static String to create the keys
  • You'll know what type of object to retrieve (Using key you have to cast)

Do you see any problem I might went over? Or does anything go against best practices?

share|improve this question

1 Answer 1

For those having the same question : In Application Servers like Weblogic when doing clustering and session replication. The session is copied to other servers when its modified. To trigger this copy, it seems that the server checks the references of the objects in the session and once it detects a change replication is done. So using only one object containing other may prevent the copy to be triggered.

Not tested.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.