正確に HttpSession の有効期限が切れる時期を知りたいです (破棄されたものとは異なります)。
session.getLastAccessedTime() + (session.getMaxInactiveInterval() * 1000) が、同じセッション ID のリクエストが来るたびにセッションの有効期限がミリ秒単位で正確にわかるかどうかを調べようとしています!
javadoc から:
長い getLastAccessedTime()
Returns the last time the client sent a request associated with this session, as the number of milliseconds since midnight January 1, 1970 GMT, and marked by the time the container received the request.
int getMaxInactiveInterval()
Returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses.
以下があるとしましょう:
Treq1 - the time the container received the 1st request
(HttpSession.lastAccessedTime)
Tresp1 - the time the container sends the 1st response
Preq1 - the time period between Treq1 and Tresp1 (the time period that the server processes the 1st request
Treq2 - the time the container received the 2nd request
(HttpSession.lastAccessedTime)
Preq1req2 - the time period between Treq1 and Treq2 (the time between requests entering the container)
Presp1req2 -the time period between Tresp1 and Treq2 (the time between the 1st response exiting the container and the 2nd request entering the container)
では、サーバーがセッションを期限切れとして計算するのはいつですか? 条件:
1. Treq1 + maxInactiveInterval < Treq1 + Preq1req2 => maxInactiveInterval < Preq1req2
2. Tresp1 + maxInactiveInterval < Tresp1 + Presp1req2 => maxInactiveInterval < Presp1req2
この部分the servlet container will keep this session open between client accesses
は、少し紛らわしいです。リクエストがコンテナに入る間、またはレスポンスが出てからリクエストが入る間を意味しますか?
余談ですが、セッションが有効期限の正確な時間に破棄されない可能性があることはわかっていますが、コンテナでリクエスト処理ロジックが発生する前にセッションが破棄されるかどうかはまだわかりません。期限切れのセッション ID を保持するリクエストについて言及しています。
敬具、
デスポット