ysfseu
ysfseu

Reputation: 676

Store an object in session

I write the following code to store an object to the HttpSession:

JenaOWLModel jenaOwlModel=MyModelFactory.getJenaModel();
HttpSession session = request.getSession(true); 
session.setAttribute("jenamodel", jenaOwlModel);

And get the oject in another servlet through the following code:

HttpSession session = request.getSession(true);
JenaOWLModel model=(JenaOWLModel)session.getAttribute("jenamodel");

It works well, but I want to know if the object I get from the session is the same object I put into the session or it's just a copy . If I change the object I got from the session, whether the object in session will also change? If it changes, will it need to synchronized the object in session by myself.Whether the tomcat provide a mechanism to synchronized the object in session automatically?

Upvotes: 0

Views: 2878

Answers (1)

user207421
user207421

Reputation: 311050

If I change the object I got from the session, whether the object in session will also change?

It's the same object, so of course it will change.

If it changes, will it need to synchronized the object in session by myself.

Yes.

Whether the tomcat provide a mechanism to synchronized the object in session automatically?

No.

Upvotes: 1

Related Questions