我想知道什麼時候究竟是一個HttpSession會不會過期(不一樣破壞)?何時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的請求。
親切的問候,
暴君
爲什麼這很重要?請求的時間通常是幾毫秒。會話超時通常爲30分鐘。 30,000或30.002是否重要?你最終的目標是什麼?無論如何,答案是在問題:*和容器收到請求時標記* –
它很重要,因爲我想知道客戶端到底什麼時候會過期。 「答案在於:容器收到請求的時間標記」這可能只涉及lastAccessedTime。你確定過期時間將會是session.getLastAccessedTime()+(session.getMaxInactiveInterval()* 1000)(1. case)嗎?有沒有可以證實的來源?感謝您的評論! – despot
你想要精確到毫秒?最終用戶在30分鐘或30分鐘和8毫秒時是否在意護理?無論如何,該會話當時不會被銷燬,因爲容器通常使用後臺線程,每隔一分鐘左右銷燬過期的會話。 –