웹서버는 servletcontext라는 공간을 가지고 있다.
request,session처럼 무언가를 넣어 둘수 있는 공간이지만, 다른 점은 웹서버가 시작되면서 초기화되고, was가 중지되면서 destroy된다. javax.servlet.ServletContextListener의 다음 메소드로 체크해 낼수있다.
Method Summary | |
void |
contextDestroyed(ServletContextEvent sce) Notification that the servlet context is about to be shut down. |
void |
contextInitialized(ServletContextEvent sce) Notification that the web application initialization process is starting. |
문제는 reload이다.
웹서버에서 자체적으로 reloading을 지원하거나, DD(web.xml)의 변경시에 자동으로 웹서버가 재구동되는 종류의 웹서버일때이다.
context를 통해 무언가 생성했다면, 그 객체가 아직 존재하고 있는지 체크를 할 필요가 있다. VM자체가 새로 구동되는 것이 아니기 때문이다.
물론 ServletContextListener에서 싱글톤을 사용하여 생성하였다면 문제는 없어진다.