how not to extend the application session time for every server call? - spring

how can we keep application session constant without extending it for every server side call ? I am using spring-session library for appplication session handling.

Related

is it possible to get the same connection from connection pool with the context?

Is it possible to get the same connection from the connection pool with the context?
Basically you can think of this scenario to understand the reason of the question; I have a Spring Boot app, within that Spring Boot app, there are RESTful services. When there is a request to RESTful services, I get the current connection via Aspect programming and I execute a stored procedure to set user details, so that I can use the user details in DB within the connection.
Currently there is an unwanted behavior; and that can occur if the two request to the RESTful services are executed within the same connection. This unwanted behavior happens rarely, so I assumed that two different requests are executed within the same connection.

Open Session In View OSIV - Does this happen for every request / thread?

I have turned off the OSIV in a Spring project as I have been reading why it (controversially) may be a bit of an anti-pattern. Not wanting to poke that debate as I have seen it gets heated but I am more interested/lost in the technicals.
Either way, I was wondering exactly when does a session become opened? Is it for ANY web request that comes in or is there some way the application knows that it will only be needing a session for certain endpoints? I am guessing the OSIV Filter is basically always called for every request and a hibernate session to the DB is aquired and added to the webrequest/thread?
I.e. is it OSIV for everything or only certain requests get the session bound through the
entire filter chain and then the controller/services and back out?
When they say "session" I am right in assuming that means it has gotten an active jdbc connection and opened connection to the database...even if I may not use it, and that is where the sort of blocking IO problems could occur say if we are waiting on 3rd party responses although we are now out of a #Transactional service method boundary and we get a spike in traffic?
What exactly is opened session wise? Is a database transaction started via the session "just in case" on every request? Or is there just a hibernate session created for each request and then a transaction is only started if a JPA/Hibernate query is started somewhere along the request (with or without #Transactional).
Any clarification would be excellent!
Vlad Mihalcea - OSIV Anti-Pattern
Baeldung - OSIV
Transactions are only started when you run a method annotated with #Transactional. OSIV just eagerly opens/creates a Hibernate session which can be used for lazy loading through out the whole request lifecycle, but the connection is only acquired lazily i.e. on first database access. Once it is acquired, it depends on certain settings when the connection will be released, but usually it is kept open until the session closes.

Do I need to call setAttribute() for every change if I use Spring Session?

I am in the progress of migrate my spring mvc + hibernate based application to clustered environment (Tomcat clustering). I am researching on the possible solutions for the session replication / sharing. From the Terracotta documentation
All clustered session implementations (including terracotta Sessions)
require a mutated session object be put back into the session after
it's mutated. If the call is missing, then the change isn't known to
the cluster, only to the local node. For example:
Session session = request.getSession();
Map m = session.getAttribute("foo");
m.clear();
session.setAttribute("foo", m); // Without this call, the clear() is not effective across the cluster.
Just want to know if the same rule holds true for Spring Session? I mean the Spring Session Project
Anyone knows the reason behind this rule? Is it because only when that method is called, Spring Session or Terracotta Web Session serialize the attribute object? Without this call, they don't know the object has changed? i.e. they won't monitor the object for changes?
Do you know a clustering solution that don't have this rule?

Can we extend liferay session through Java Code?

Can we extend session through Java Code?
I found the code to extend the session through javascript. But I've doubt , Can we extend session through Java Code? I need to extend the session through java only.
Can anyone help me???
Thanks.
The session is maintained by the application server. If you need longer sessions, you can configure them in your appserver.
The application server implicitly extends a session whenever it sees a http request with that session id, that's why extending the session through javascript works: It just triggers some http request and counts on the side effect of extending the session.
On an application server you typically don't have custom threads running anyway, so you shouldn't count on this to help you. It's the wrong place to solve the problem
No you can not extend session timeout through Java because session is maintained by application server.
If you want to extned sesseion, you can configured them in application server.

Performance overhead of using IoC containers with MVC3

I have an MVC3 application that I hope will be serving a large number of user requests. I would like to use an IoC container but don't want it to slow down the performance of my application.
I read that I shouldn't be concerned as the only overhead is at the time of initialization. However for an MVC3 application is this not EVERY time a user requests a new web page?
No, it is not every time the user requests a page. The IoC container should be configured once for the lifetime of the application (in your global Application_Start event handler, for instance) and then shouldn't require any additional configuration while the application runs.

Resources