IT TIP

web.xml의 세션 시간 초과

itqueen 2020. 11. 30. 20:29
반응형

web.xml의 세션 시간 초과


세션 시간 초과에 대해 Web.xml에서 세션 구성의 실제 목적을 이해하려고합니다.

<!-- Session Configuration -->
<session-config>
        <session-timeout>60</session-timeout>
</session-config>

이제 제 질문에 대해 말씀 드리겠습니다.

내 응용 프로그램에서 .txt 파일을 가져 오거나 업로드하는 중입니다. 가져 오는 데 수백만 개의 레코드가 있으므로 1 시간 이상이 소요됩니다. 그러나 내 응용 프로그램이 여전히 진행중인 .txt 파일을 가져오고 있지만 세션은 1 시간 후에 시간 초과됩니다. 애플리케이션이 백그라운드에서 일부 작업을 수행하므로 이러한 애플리케이션은 시간 초과되지 않아야합니다.


만료되지 않는 세션 타임 아웃을 설정하는 것은 바람직하지 않습니다. 사용자가 작업을 마칠 때마다 로그 아웃 버튼을 눌러 서버의 부하가 너무 많이 발생하는 것을 방지 할 수 있기 때문입니다 (사용자 및 하드웨어에 따라 다름). 추가로 피하고 싶은 몇 가지 보안 문제가 있습니다.

서버가 작업을 수행하는 동안 세션이 무효화되는 이유는 예를 들어 http 요청을 통해 클라이언트 측 (사용자 브라우저)과 서버 측간에 통신이 없기 때문입니다. 따라서 서버는 사용자 상태에 대해 알 수없고, 그가 유휴 상태라고 생각하고에 설정된 시간이 지나면 세션을 무효화합니다 web.xml.

이 문제를 해결하려면 몇 가지 가능성이 있습니다.

  • 당신은 할 수 작업이 세션을 터치 실행되는 동안 백엔드를 그리고 만료되는 것을 방지
  • <session-timeout>서버 내부를 늘리지 만 권장하지 않습니다.
  • 작업하는 동안 세션을 터치 (확장)하거나 스레드가 완료되면 사용자에게 알리는 전용 스레드에서 작업을 실행합니다.

비슷한 질문이있었습니다. 아마도이 솔루션의 일부를 프로젝트에 적용 할 수있을 것입니다. 이것 좀보세요 .

이것이 도움이되기를 바랍니다.


<session-config>
    <session-timeout>-1</session-timeout>
</session-config>

세션이 만료되지 않는 경우 "-1"을 사용할 수 있습니다. 스레드가 완료되는 데 걸리는 시간을 모르기 때문입니다.


파일 업로드가 완료 될 때까지 서버와의 세션을 유지하기 위해 자바 스크립트를 통해 주기적으로 (예 : 60 초에 한 번) 서버에 AJAX Http 요청을 보냅니다.


해킹 방법 :

대규모 업 / 다운로드가 예상되는 경우 프로그래밍 방식으로 세션 시간 초과를 늘릴 수 있습니다.

session.setMaxInactiveInterval(TWO_HOURS_IN_SECONDS)

프로세스가 종료되면 시간 제한을 다시 기본값으로 설정할 수 있습니다.

그러나 .. Java EE를 사용 중이고 업 / 다운로드에 1 시간이 걸리지 않을 때 더 좋은 방법은 작업을 비동기식으로 실행하는 것입니다 (예 : JMS를 통해).


질문에 대한 답변으로 많은 옵션을 볼 수 있지만 세션이 만료되지 않는 경우 "-1"을 사용할 수 있습니다. 스레드가 완료되는 데 걸리는 시간을 모르기 때문입니다. 예 :

   <session-config>
        <session-timeout>-1</session-timeout>
    </session-config>

또는 어떤 목적으로 시간 초과가 발생하지 않도록하려면 :

<session-config>
    <session-timeout>0</session-timeout>
</session-config>

또 다른 옵션은 bla, bla, bla 등과 같이 숫자를 1000으로 늘릴 수 있습니다.

그러나 정말로 중지하고 싶고 애플리케이션에서 사용자를 강제로 로그 아웃시킬 필요가 없다고 생각하는 경우 로그 아웃 버튼을 추가하면 사용자가 언제 떠날 지 결정할 것입니다.

강제로 로그 아웃 할 필요가없고 서버와 컴퓨터 속도 및 파일 크기에 따라 시간이 걸릴 수있는 파일을로드하는 경우 문제를 해결하기 위해 다음을 수행 할 수 있습니다.

<!-- sets the default session timeout to 60 minutes. -->
   <!-- <session-config>
     <session-timeout>60</session-timeout>
   </session-config> -->

댓글을 달거나 삭제하면됩니다! 탄 타라 란탄, 탄 탄!


<session-config>
        <session-timeout>-1</session-timeout>
</session-config>

In the above code "60" stands for the minutes. The session will expired after 60 minutes. So if you want to more time. For Example -1 that is described your session never expires.


The docs says:

The session-timeout element defines the default session timeout interval for all sessions created in this web application. The specified timeout must be expressed in a whole number of minutes. If the timeout is 0 or less, the container ensures the default behaviour of sessions is never to time out. If this element is not specified, the container must set its default timeout period.


you can declare time in two ways for this problem..

1) either give too long time that your file reading is complete in between that time.

<session-config>
    <session-timeout> 1000 </session-timeout>
</session-config>

2)declare time which is never expires your session.

<session-config>
    <session-timeout>-1</session-timeout>
</session-config>

Another option I would recommend is to create a separate application that is stateless that would take the large file. On your main app open a new window or iframe that will accept the file and send it through that window then hide the window or iframe once the upload has started using Javascript.


If you don't want a timeout happening for some purpose:

<session-config>
    <session-timeout>0</session-timeout>
</session-config>

Should result in no timeout at all -> infinite


You should consider splitting the large file to chunks and rely on multi threading capabilities to process more than one file at a time OR let the whole process run as a background task using TimerTask and write another query to know the status of it form the browser including a progress bar can be shown if you can know the process time of a file or record.


Usually the session will not expire when request processing is happening. I think there is an LB or something in between which reads the entire file and then invokes the web container.

This might be causing a delay which is leading to expiry of the session.

참고URL : https://stackoverflow.com/questions/15382895/session-timeout-in-web-xml

반응형