0

Is serialization necessary while writing and reading an object in the same JVM?

Session objects must implement serializable in order to maintain it after restart of server.

As same JVM is used why session objects must implement serializable?

seenukarthi
  • 8,241
  • 10
  • 47
  • 68
  • 1
    Serialization is used when you have to send and receive the object across the network. It is independent of the JVM implementation. – Zahid Khan Apr 05 '22 at 09:42
  • @ZahidKhan (Java) serialization is turning Java objects into bytes. Whether you send those bytes over the network is a separate thing. You might as well save them to a file or database (as is done to sessions), or do anything else you would do to bytes (including sending over the network). – Kayaman Apr 05 '22 at 09:53
  • Yes, @Kayaman that's the correct definition. What I tried to convey is - that it is independent of JVM. – Zahid Khan Apr 05 '22 at 16:39

1 Answers1

0

Serialization is required because the session objects may be stored in a file, a database or may be transported to another service node via network. Even the included objects must implement Serializable.

Why these requirements were set? Because a session must last longer than a request. Nobody can guarantee that the same JVM will still exist when the next request comes with the same Session ID - so there should be a redundancy or failover solution that ensures that the session will survive. There are many solutions for this, but the actual solution doesn't even matter - but Serialization ensures that it will work.

gaborsch
  • 15,408
  • 6
  • 37
  • 48